diff --git a/src/cache-base.ts b/src/cache-base.ts index 0ed97b1d..c6b5e953 100644 --- a/src/cache-base.ts +++ b/src/cache-base.ts @@ -204,26 +204,16 @@ export class GradleStateCache { fs.writeFileSync(initScriptPath, initScriptContent) } - // Copy the toolchains.xml file to `~/.m2` + // Copy the toolchain definitions file to `~/.m2/toolchains.xml` (if the file doesn't already exist) const m2dir = path.resolve(this.userHome, '.m2') - fs.mkdirSync(m2dir, {recursive: true}) - core.info(`Created m2 directory ${m2dir}`) - - const settingsXml = path.resolve(m2dir, 'settings.xml') - if (fs.existsSync(settingsXml)) { - const existingSettings = fs.readFileSync(settingsXml, 'utf8') - core.info("Found existing settings.xml with content:") - core.info(existingSettings) - } - const toolchainXmlTarget = path.resolve(m2dir, 'toolchains.xml') - if (fs.existsSync(toolchainXmlTarget)) { - const existingToolchains = fs.readFileSync(toolchainXmlTarget, 'utf8') - core.info("Found existing toolchains.xml with content:") - core.info(existingToolchains) + if (!fs.existsSync(toolchainXmlTarget)) { + fs.mkdirSync(m2dir, {recursive: true}) + const toolchainContent = this.readInitScriptAsString('toolchains.xml') + fs.writeFileSync(toolchainXmlTarget, toolchainContent) + + core.info(`Wrote default JDK locations to ${toolchainXmlTarget}`) } - const toolchainContent = this.readInitScriptAsString('toolchains.xml') - fs.writeFileSync(toolchainXmlTarget, toolchainContent) } private readInitScriptAsString(resource: string): string { diff --git a/src/resources/init-scripts/toolchains.xml b/src/resources/init-scripts/toolchains.xml index ec87a4ec..f9ba374c 100644 --- a/src/resources/init-scripts/toolchains.xml +++ b/src/resources/init-scripts/toolchains.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- JDK Toolchains installed by default on GitHub-hosted runners --> <toolchains> + <!-- JDK Toolchains installed by default on GitHub-hosted runners --> <toolchain> <type>jdk</type> <provides>