Backport #1111: Preserve Maven toolchains across repeated setup-java runs (#1099)#1113
Merged
Merged
Conversation
Backport of #1111 to releases/v5. Toolchain generation was gated behind the `overwrite-settings` input, which is documented to control only regeneration of `settings.xml`. Because `generateToolchainDefinition` already performs a non-destructive merge (existing JDK, custom, and user-managed toolchains are preserved, and only an entry with the same `type` + `provides.id` is replaced), skipping the write when `overwrite-settings: false` caused later setup-java executions to drop toolchain entries registered by earlier runs. Decouple toolchains generation from `overwrite-settings`: the toolchains file is now always written, so consecutive runs accumulate every JDK. `settings.xml` behavior (auth.ts) is unchanged. - src/toolchains.ts: drop overwriteSettings from configureToolchains / createToolchainsSettings / writeToolchainsFileToDisk; always write. - __tests__/toolchains.test.ts: update call sites, rewrite the "does not overwrite" test to assert non-destructive extension, and add a regression test for consecutive configureToolchains executions. - docs/advanced-usage.md: clarify merge is non-destructive and independent of overwrite-settings. - dist/setup/index.js: rebuilt. Fixes #1099 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR backports the fix for #1099 to releases/v5, ensuring repeated setup-java executions in the same job do not drop previously-registered Maven toolchain entries in ~/.m2/toolchains.xml.
Changes:
- Always write
toolchains.xmlafter performing the non-destructive merge, removing the incorrect gating onoverwrite-settings. - Update and extend the toolchains test suite, including a regression test covering multiple consecutive
configureToolchainsruns. - Clarify documentation around non-destructive toolchain merging and the fact that it’s independent of
overwrite-settings; rebuild the bundleddistoutput.
Show a summary per file
| File | Description |
|---|---|
| src/toolchains.ts | Removes overwrite-settings gating so merged toolchains are always persisted across multiple runs. |
| tests/toolchains.test.ts | Updates call sites and adds regression coverage to ensure toolchains accumulate without duplication. |
| docs/advanced-usage.md | Documents that toolchain merging is non-destructive and independent of overwrite-settings. |
| dist/setup/index.js | Rebuilt distribution output reflecting the source changes. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/4 changed files
- Comments generated: 1
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of #1111 to the
releases/v5branch. Fixes #1099.Running
setup-javamultiple times in the same job (matrix builds or multiplejava-versionvalues) could drop toolchain entries registered by earlier runs, leaving only one JDK in~/.m2/toolchains.xml.Root cause
Toolchains generation was gated behind the
overwrite-settingsinput. Whenoverwrite-settings: false,writeToolchainsFileToDiskskipped writing entirely if the file already existed — so a secondsetup-javarun never persisted its JDK, silently discarding the merged result.This gating was inappropriate because:
overwrite-settingsis documented (inaction.yml) to control regeneration ofsettings.xmlonly.generateToolchainDefinitionalready performs a non-destructive merge: existing JDK, custom, and user-managed toolchains are preserved, and only an entry with the exact sametype+provides.idis replaced.So writing the toolchains file is always safe and should not be blocked.
Changes
src/toolchains.ts: RemoveoverwriteSettingsfromconfigureToolchains,createToolchainsSettings, andwriteToolchainsFileToDisk. The toolchains file is now always written (non-destructively).settings.xmlbehavior inauth.tsis unchanged.__tests__/toolchains.test.ts: Update call sites, rewrite the "does not overwrite" test to assert non-destructive extension, and add a regression test that runsconfigureToolchainsthree times and asserts every JDK is preserved with no duplicates.docs/advanced-usage.md: Clarify that the merge is non-destructive and independent ofoverwrite-settings.dist/setup/index.js: Rebuilt.Backport notes
releases/v5predates the ESM migration onmain, so the change was re-applied to v5's CommonJS sources rather than cherry-picked (imports use./util/./constantswithout.js, and the new regression test usesjest.spyOn(core, 'getInput')to match v5's mocking style instead ofunstable_mockModule). The net behavioral change is identical to #1111.Testing
npm run build, format-check, and lint all pass.npm test: thetoolchainssuite passes (15/15), including the new regression test; full suite passes on clean runs.Fixes #1099
Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com