Sitelet https://github.com/apache/maven/pull/13025
Skip to content

[Backport 4.0.x] Fix ToolchainPluginStrategy to detect inherited source levels from parent POMs - #13025

Merged
gnodet merged 1 commit into
apache:maven-4.0.xfrom
gnodet:backport/12973-to-4.0.x
Sep 2, 2026
Merged

gnodet merged 1 commit into
apache:maven-4.0.xfrom
gnodet:backport/12973-to-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Backport of #12973 to maven-4.0.x.

Cherry-pick of 2144fbd.

…rent POMs

* Fix ToolchainPluginStrategy to detect inherited source levels from parent POMs

When a project inherits --source/--release from a remote parent POM
(e.g. org.apache.sling:sling-parent setting --source 6), mvnup's
ToolchainPluginStrategy failed to detect it because detectSourceLevel()
only inspected the local POM XML DOM. This caused mvnup to skip adding
the toolchains plugin, leading to Maven 4 build failures.

Changes:
- Share the Maven 4 API Session across all strategy instances (DCL
  singleton) so the Session's RequestCache deduplicates effective model
  builds across PluginUpgradeStrategy, ToolchainPluginStrategy, and
  CompatibilityFixStrategy
- Route buildEffectiveModel() through InternalSession.request() to
  leverage the RequestCache
- Add effective model fallback in ToolchainPluginStrategy: when local
  POM has no source level, resolve the effective model to pick up
  inherited compiler configuration from parent POMs
- Add 8 new tests for effective model source level detection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Extract MvnupSessionHolder with @provides @singleton Session producer

Move the Maven 4 API Session creation from AbstractUpgradeStrategy
into a dedicated MvnupSessionHolder class that uses @provides
@singleton to produce the Session as a DI-managed bean. The DI
container calls createSession() once and injects the singleton
Session into all strategy instances via @Inject @nAmed("mvnup")
field injection on the abstract base class.

This replaces the manual DCL singleton pattern with proper DI
lifecycle management. A static fallback in getSession() preserves
backward compatibility for unit tests that instantiate strategies
directly (without DI).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Address review: add groupId check in effective model plugin detection and fix Javadoc accuracy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet added this to the 4.0.0-rc-7 milestone Sep 2, 2026
@gnodet gnodet self-assigned this Sep 2, 2026
@gnodet
gnodet merged commit f2afd82 into apache:maven-4.0.x Sep 2, 2026
22 checks passed
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@gnodet Please assign appropriate label to PR according to the type of change.

@gnodet gnodet added bug Something isn't working mvn4 backport labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug Something isn't working mvn4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant