Skip to content

Commit

Permalink
Copy the raw JDK path into toolchains.xml
Browse files Browse the repository at this point in the history
Previously we were relying on Gradle to substitute JDK environment variables
in toolchains.xml. With this change, the actual path to the JDK is encoded instead.
This should avoid issues where Gradle is not able to successfully resolve the
envioronment variable.
  • Loading branch information
bigdaz committed Jan 20, 2025
1 parent 392620b commit faf1d7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions sources/src/caching/gradle-user-home-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export function getPredefinedToolchains(): string | null {
// Get the version and path for each JAVA_HOME env var
const javaHomeEnvs = Object.entries(process.env)
.filter(([key]) => key.startsWith('JAVA_HOME_') && process.env[key])
.map(([key, _value]) => ({
.map(([key, value]) => ({
jdkVersion: key.match(/JAVA_HOME_(\d+)_/)?.[1] ?? null,
jdkPath: `\${env.${key}}`
jdkPath: value as string
}))
.filter(env => env.jdkVersion !== null)

Expand All @@ -40,7 +40,9 @@ ${javaHomeEnvs
<configuration>
<jdkHome>${jdkPath}</jdkHome>
</configuration>
</toolchain>`).join('\n')}
</toolchain>`
)
.join('\n')}
</toolchains>\n`
}

Expand Down
12 changes: 6 additions & 6 deletions sources/test/jest/predefined-toolchains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('predefined-toolchains', () => {
<version>8</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_8_X64}</jdkHome>
<jdkHome>/jdks/foo_8</jdkHome>
</configuration>
</toolchain>
<toolchain>
Expand All @@ -48,7 +48,7 @@ describe('predefined-toolchains', () => {
<version>11</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_11_X64}</jdkHome>
<jdkHome>/jdks/foo_11</jdkHome>
</configuration>
</toolchain>
<toolchain>
Expand All @@ -57,7 +57,7 @@ describe('predefined-toolchains', () => {
<version>21</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_21_ARM64}</jdkHome>
<jdkHome>/jdks/foo_21</jdkHome>
</configuration>
</toolchain>
</toolchains>
Expand All @@ -81,7 +81,7 @@ describe('predefined-toolchains', () => {
<version>8</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_8_X64}</jdkHome>
<jdkHome>/jdks/foo_8</jdkHome>
</configuration>
</toolchain>
</toolchains>
Expand All @@ -98,7 +98,7 @@ describe('predefined-toolchains', () => {
<version>8</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_8_X64}</jdkHome>
<jdkHome>/jdks/foo_8</jdkHome>
</configuration>
</toolchain>
Expand All @@ -109,7 +109,7 @@ describe('predefined-toolchains', () => {
<version>11</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_11_X64}</jdkHome>
<jdkHome>/jdks/foo_11</jdkHome>
</configuration>
</toolchain>
</toolchains>
Expand Down

0 comments on commit faf1d7c

Please sign in to comment.