Skip to content

fix: mvnup ToolchainPluginStrategy computes reactor-wide minimum source level (#14166) - #14168

Open
gnodet wants to merge 2 commits into
apache:masterfrom
gnodet:fix/14166-toolchain-reactor-min-source-level
Open

gnodet wants to merge 2 commits into
apache:masterfrom
gnodet:fix/14166-toolchain-reactor-min-source-level

Conversation

@gnodet

@gnodet gnodet commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

ToolchainPluginStrategy now computes the reactor-wide minimum source level before
deciding whether (and where) to inject maven-toolchains-plugin.

Root Cause

The strategy was processing each POM independently and using that POM's own declared
source level to decide whether to inject maven-toolchains-plugin.

In a multi-module project where the root POM declares source=8 (not retired) and
a child module declares source=5 (retired — no longer accepted by JDK ≥ 9), the
root POM was always skipped because latestJdkForSourceLevel(8) == -1. The child
would correctly receive the toolchain, but the root POM (the natural injection point
for toolchain configuration that applies to all modules) was left unmodified.

Real-world projects affected include apache/incubator-samoa, portals-pluto, and
tomee-release-tools, all of which have root source=8 with one or more child
modules using source=4 or source=5.

Fix

The single-pass loop is replaced with a three-pass approach:

  1. Pass 1 — collection: gather {pomPath → detectedSourceLevel} for every POM
    in the reactor (using the existing local-first + effective-model-fallback detection).

  2. Pass 2 — reactor minimum: compute the minimum source level across all entries.

  3. Pass 3 — injection: for each POM that declares a source level, determine the
    effective JDK bound as min(ownLevel, reactorMin):

    • A POM whose own level is not retired but whose reactor minimum is retired
      now also receives the toolchain (fixes the root-POM gap).
    • A POM whose own level is retired still uses the stricter reactor minimum
      when available.
    • POMs with no declared source level are still skipped.

Tests

Three new unit tests cover:

Test Scenario
addsToolchainToRootWhenChildHasRetiredLevel Root source=8, child source=5 → both modified with (,8]
noToolchainWhenOnlyRootHasNonRetiredLevel Root source=8, child no source → neither modified
usesReactorMinimumWhenRootHasHigherRetiredLevel Root source=7, child source=5 → both use (,8] (child's stricter bound)

Fixes #14166


Hermes Agent (Claude Sonnet 4.5) on behalf of Guillaume Nodet

Guillaume Nodet added 2 commits November 28, 2026 13:56
…ce level (apache#14166)

ToolchainPluginStrategy was processing each POM independently and
using that POM's own declared source level to decide whether to inject
the maven-toolchains-plugin.  When the root POM declared source=8 (not
retired), it was always skipped — even when a child module in the same
reactor declared a retired source level (e.g. source=5, retired since
JDK 9) that requires a toolchain.

Fix: replace the single-pass per-POM loop with a two-pass approach:

Pass 1 — collect the source level from every POM in the reactor
  (using the same local-first + effective-model-fallback detection
  already in place).

Pass 2 — compute the reactor-wide minimum source level.

Pass 3 — apply toolchain plugin to each POM that declares a source
  level, using the most restrictive (lowest) bound from the reactor:
  - A POM whose own level is not retired but whose reactor minimum is
    retired now receives the toolchain (fixes the root-POM case).
  - A POM whose own level is already retired uses the reactor minimum
    when it is even more restrictive.
  - POMs that declare no source level at all are still skipped.

Fixes apache#14166
The IT test MavenITgh12922MvnupToolchainPluginStrategyTest verifies the
log contains 'Added maven-toolchains-plugin with select-jdk-toolchain
goal', which is the upstream message. My previous commit mistakenly
changed the message to 'maven-toolchains-plugin addition', breaking the
IT on all 9 OS/JDK matrix combinations.
@gnodet
gnodet marked this pull request as ready for review November 28, 2026 17:56

@gnodet-bot gnodet-bot 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.

Correct reactor-wide minimum source level computation. The 3-pass approach (collect → compute min → apply) is clean, all edge cases are handled (mixed retired/non-retired, only non-retired, both retired at different levels), and the test coverage hits the important scenarios. LGTM.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Document childDoc = Document.of(childPomXml);
UpgradeContext context = TestUtils.createMockContext();

Map<Path, Document> pomMap = new java.util.LinkedHashMap<>();

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.

🔹 Nit: FQCN instead of import — java.util.LinkedHashMap is used as a fully-qualified name in three test methods instead of an import. Minor style inconsistency; the production code properly imports its types. Same pattern at lines ~718 and ~763.

Suggested change
Map<Path, Document> pomMap = new java.util.LinkedHashMap<>();
Map<Path, Document> pomMap = new LinkedHashMap<>();

(with import java.util.LinkedHashMap; in the imports section)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mvnup: ToolchainPluginStrategy misses retired source levels declared in child modules (reactor-wide minimum not computed)

2 participants