Skip to content

Commit

Permalink
Inform Gradle where to locate pre-installed JDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Aug 20, 2023
1 parent b17d107 commit a07019c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/integ-test-detect-java-toolchains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,27 @@ jobs:
run: |
grep -q 'Eclipse Temurin JDK 16' output.txt || (echo "::error::Did not detect setup-java installed JDK 16" && exit 1)
grep -q 'Eclipse Temurin JDK 20' output.txt || (echo "::error::Did not detect setup-java installed JDK 20" && exit 1)
# Test that predefined JDK detection property is not overwritten by action
check-no-overwrite:
strategy:
matrix:
os: ${{fromJSON(inputs.runner-os)}}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Download distribution if required
uses: ./.github/actions/download-dist
- name: Configure java installations env var in Gradle User Home
shell: bash
run: |
mkdir -p ~/.gradle
echo "org.gradle.java.installations.fromEnv=XXXXX" > ~/.gradle/gradle.properties
- name: Setup Gradle
uses: ./
- name: Check gradle.properties
shell: bash
run: |
cat ~/.gradle/gradle.properties
grep -q 'org.gradle.java.installations.fromEnv=JAVA_HOME' && exit 1
16 changes: 16 additions & 0 deletions src/cache-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ export class GradleStateCache {
}

private initializeGradleUserHome(gradleUserHome: string, initScriptsDir: string): void {
// Ensure that pre-installed java versions are detected. Only add property if it isn't already defined.
const gradleProperties = path.resolve(gradleUserHome, 'gradle.properties')
const existingGradleProperties = fs.existsSync(gradleProperties)
? fs.readFileSync(gradleProperties, 'utf8')
: ''
if (!existingGradleProperties.includes('org.gradle.java.installations.fromEnv=')) {
fs.appendFileSync(
gradleProperties,
`
# Auto-detect pre-installed JDKs
org.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64
`
)
}

// Copy init scripts from src/resources
const initScriptFilenames = [
'build-result-capture.init.gradle',
'build-result-capture-service.plugin.groovy',
Expand Down

0 comments on commit a07019c

Please sign in to comment.