Skip to content

fix: Maven Toolchains grows unexpectedly#534

Open
Okeanos wants to merge 4 commits into
actions:mainfrom
Okeanos:fix-maven-toolchains-duplication
Open

fix: Maven Toolchains grows unexpectedly#534
Okeanos wants to merge 4 commits into
actions:mainfrom
Okeanos:fix-maven-toolchains-duplication

Conversation

@Okeanos

@Okeanos Okeanos commented Sep 19, 2023

Copy link
Copy Markdown
Contributor

Description:
On self-hosted runners toolchains.xml may survive multiple runs and unexpectedly grow as a result of the toolchains setup simply appending the JDK definition even if one with the same type and provides.id already exists.

Restructuring the parsing step and filtering the potentially existing list of toolchain definitions prevents this and also fixes toolchain.xml files that already contain duplicates.

There is one open TODO concerning the recreation of the toolchains-root node in the xml if an existing toolchains.xml was parsed. That could and potentially should be handled better and I am open to suggestions.

Related issue:
#530

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

@Okeanos Okeanos requested a review from a team as a code owner September 19, 2023 22:23
@IvanZosimov IvanZosimov linked an issue Sep 20, 2023 that may be closed by this pull request
5 tasks
@Okeanos Okeanos force-pushed the fix-maven-toolchains-duplication branch from 82fce8d to c30cb6d Compare November 29, 2023 18:55
@Okeanos Okeanos force-pushed the fix-maven-toolchains-duplication branch from c30cb6d to b8162e8 Compare December 9, 2023 10:35
@fpiresca

Copy link
Copy Markdown

Hey guys, this is a potential fix for my case. I would appreciate if we can test this out or merged it.

@Okeanos Okeanos force-pushed the fix-maven-toolchains-duplication branch from b8162e8 to e53962a Compare November 19, 2024 19:40
@Okeanos Okeanos force-pushed the fix-maven-toolchains-duplication branch from e53962a to d823120 Compare August 14, 2025 08:24
@Okeanos Okeanos force-pushed the fix-maven-toolchains-duplication branch from d823120 to 301593b Compare November 24, 2025 18:37
On self-hosted runners toolchains.xml may survive multiple runs and unexpectedly
grow as a result of the toolchains setup simply appending the JDK definition
even if one with the same `type` and `provides.id` already exists.

Restructuring the parsing step and filtering the potentially existing list of
toolchain definitions prevents this and also fixes toolchain.xml files that
already contain duplicates.

Fixes actions#530
@brunoborges brunoborges force-pushed the fix-maven-toolchains-duplication branch from 301593b to 36b7a1c Compare June 22, 2026 16:30
@brunoborges

Copy link
Copy Markdown
Contributor

@Okeanos I rebased this branch on current main and resolved the merge conflicts. Could you please verify that the updated changes still match your intent and behavior for #530?

@brunoborges brunoborges added feature request New feature or request to improve the current logic bug Something isn't working maven Maven settings, toolchains, and publishing auth and removed feature request New feature or request to improve the current logic labels Jun 22, 2026
@Okeanos

Okeanos commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@brunoborges I'll have a look in a day or two I hope. Didn't have the time since the last release to fix this yet. Thanks for helping out with the rebase.

Feel free to look at #553 first and I'll update my PR after if you can already merge that.

@brunoborges

Copy link
Copy Markdown
Contributor

Linking the tracking issue: this PR implements #530 (Maven toolchains.xml unexpected growth). Maintainers — adding Closes #530 to the PR description will auto-close the issue on merge.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Maven toolchains.xml “overgrowth” on self-hosted runners by parsing existing toolchain entries and filtering out duplicate JDK toolchains (same type + provides.id) before writing the updated file.

Changes:

  • Parse existing toolchains.xml into JS objects and merge with the new JDK toolchain entry.
  • Deduplicate JDK toolchain definitions (while leaving non-JDK toolchains untouched).
  • Expand unit tests to cover deduplication and preservation of custom toolchain elements; update the compiled dist/ output accordingly.
Show a summary per file
File Description
src/toolchains.ts Refactors toolchains generation to parse existing XML, merge toolchains, and deduplicate JDK entries.
dist/setup/index.js Updates the compiled action bundle to reflect the new toolchains logic.
__tests__/toolchains.test.ts Adds/updates tests for deduplication behavior and preservation of custom toolchain content.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/3 changed files
  • Comments generated: 2

Comment thread src/toolchains.ts
Comment on lines +118 to +126
jsToolchains = jsToolchains.filter(
(value, index, self) =>
// ensure non-jdk toolchains are kept in the results, we must not touch them because they belong to the user
value.type !== 'jdk' ||
index ===
self.findIndex(
t => t.type === value.type && t.provides.id === value.provides.id
)
);
Comment thread src/toolchains.ts
Comment on lines +129 to +136
// TODO: technically bad because we shouldn't re-create the toolchains root node (with possibly different schema values) if it already exists, however, just overriding the toolchain array with xmlbuilder2 is … uh non-trivial
return xmlCreate({
toolchains: {
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'@xsi:schemaLocation':
'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
toolchain: jsToolchains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working maven Maven settings, toolchains, and publishing auth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overgrowing of the toolchains.xml on the self-hosted runners

5 participants