gnodet opened a new issue, #14166:
URL: https://github.com/apache/maven/issues/14166

   ## Problem
   
   `ToolchainPluginStrategy` processes each POM independently and uses the 
**first source level found** in that POM (or its inherited effective model) to 
decide whether toolchain injection is needed. When the root POM declares 
`source=8` (which `JdkSourceLevelSupport.latestJdkForSourceLevel(8)` returns 
`-1` — "supported by all JDKs"), the strategy stops and injects nothing — even 
if child modules in the same reactor declare retired source levels (e.g. 
`source=4`, `source=5`).
   
   ## Concrete example
   
   `apache/incubator-samoa` (gnodet/maven4-testing #41763):
   - Root POM: `<maven.compiler.source>1.8</maven.compiler.source>` → source 8 
→ no toolchain needed
   - Child modules: `<maven.compiler.source>1.5</maven.compiler.source>` → 
source 5 → requires JDK ≤ 8 (JEP 182)
   
   Maven 3 builds with JDK 8 (`PROJECT_JDK_HOME` from the test harness) and 
succeeds. Maven 4 runs on JDK 17 (minimum), `javac` rejects `--source 5` 
("source release 5 is not supported"), and the build fails. mvnup injected no 
toolchain because it saw `source=8` on the root and stopped.
   
   Same pattern in:
   - `portals-pluto` — root `source=8`, child modules `--source 4`
   - `tomee-release-tools` — root `source=8`, child modules `--source 5`
   
   ## Root cause
   
   In `doApply()`, each `pomMap` entry is processed independently:
   
   ```java
   int sourceLevel = detectSourceLevel(pomDocument);
   if (sourceLevel <= 0) {
       sourceLevel = detectSourceLevelFromEffectiveModel(context, pomPath);
   }
   if (sourceLevel <= 0) { continue; }
   
   int latestJdk = JdkSourceLevelSupport.latestJdkForSourceLevel(sourceLevel);
   if (latestJdk <= 0) {
       // "source 8+ is not retired" — stops here, injects nothing
       continue;
   }
   ```
   
   The strategy never computes `min(sourceLevel across all pomMap entries)`. As 
soon as a POM returns a non-retired level, that POM is skipped — regardless of 
what other reactor members declare.
   
   ## Expected behavior
   
   After the per-POM detection pass, the strategy should compute the minimum 
source level across the entire reactor and use that minimum to determine 
whether toolchain injection is needed on the root POM (or on each POM that 
doesn't already have toolchain configured).
   
   Concretely: if any POM in `pomMap` declares a source level that is retired 
(regardless of what the root POM says), the toolchain plugin should be injected.
   
   ## Proposed fix
   
   Two-pass approach:
   1. First pass: collect `(pomPath, detectedSourceLevel)` for all entries 
(already happens implicitly today).
   2. After the loop: compute `minLevel = min(all positive sourceLevels)`.
   3. If `JdkSourceLevelSupport.latestJdkForSourceLevel(minLevel) > 0`, inject 
toolchain into whichever POM is the best anchor (root POM, or the POM that 
declared the lowest level).
   
   The entire `pomMap` is already in memory at `doApply()` call time — no extra 
I/O or network calls required.
   
   ## Why this is straightforward
   
   The `doApply()` method already iterates the full `pomMap`. The only missing 
piece is cross-POM aggregation of the detected source levels before making the 
injection decision. The effective model fallback 
(`detectSourceLevelFromEffectiveModel`) is already handling the "inherited from 
remote parent" case — this change handles the symmetric "declared in a local 
child" case.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to