Skip to content

[MNG-8112] Honor export descriptors from the extension classpath - #13101

Merged
gnodet merged 3 commits into
apache:masterfrom
goutamadwant:fix/mng-8112-extension-classpath-exports
Nov 6, 2026
Merged

gnodet merged 3 commits into
apache:masterfrom
goutamadwant:fix/mng-8112-extension-classpath-exports

Conversation

@goutamadwant

@goutamadwant goutamadwant commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10506.

Discover META-INF/maven/extension.xml from maven.ext.class.path in the active Maven CLI (impl/maven-cli) and include package and artifact exports in CoreExports. Exported packages become visible to plugins, and exported artifacts are filtered from plugin dependencies. The deprecated compat/maven-embedder changes have been removed.

Reuse the existing descriptor reader and preserve extension classloader isolation. Deduplicate classpath entries by real path before processing, retaining the first entry. Discover each descriptor separately so a malformed optional descriptor cannot skip later valid entries. Tests cover JARs, directories, relative and symlink aliases, malformed descriptors, and loading alongside .mvn/extensions.xml.

Validation: the classpath Core IT regressions failed against the unmodified distribution in the original PR work and pass with this fix. On the current head, mvn -B -ntp verify passed, all 11 PlexusContainerCapsuleFactoryTest cases passed, and mvn -B -ntp -Prun-its -Dits.test=MavenITmng5771CoreExtensionsTest -Dits.forkCount=2 verify passed (7 Core IT cases). The full Core IT suite passed on the earlier PR revision, before this follow-up.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Read package and artifact exports from maven.ext.class.path entries in both CLI implementations. Reuse descriptor discovery without moving extensions into the core realm or changing extension precedence.

Cover JAR and directory entries, optional descriptors, package isolation, artifact filtering, and mixed extension loading with unit tests and Core ITs.

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

Solid fix. The approach correctly reads extension.xml descriptors from -Dmaven.ext.class.path entries and feeds their exported packages/artifacts into CoreExports, so ClassRealmManager can properly filter them when building plugin realms. Both CLI implementations (compat 3.x and impl 4.x) are semantically equivalent despite their structural differences. The ordering is correct — setupContainerRealm already adds the classpath URLs to the container realm before discoverFrom is called, so descriptor scanning works against the right classloader. The list mutation in PlexusContainerCapsuleFactory is safe because setupContainerRealm makes a defensive copy.

Test coverage is thorough: unit tests verify package export visibility, artifact filtering, optional descriptors, and multi-entry classpath merging. The integration tests exercise both classpath-only and classpath-plus-extensions.xml scenarios end-to-end.

One nit below.

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

import static org.junit.jupiter.api.Assertions.assertTrue;

@Deprecated
class MavenCliExtensionClasspathTest {

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: @Deprecated marks this class itself as deprecated, which is not the intent — you want to suppress deprecation warnings from using the deprecated MavenCli. The correct annotation is @SuppressWarnings("deprecation").

Suggested change
class MavenCliExtensionClasspathTest {
@SuppressWarnings("deprecation")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gnodet-bot Replaced @Deprecated with @SuppressWarnings("deprecation"). The CLI tests and module verification pass. Thanks for catching this.

Use SuppressWarnings instead of marking the regression test itself deprecated. Keep the warning suppression scoped to the test class.

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

Re-review after 79dfab82: the @Deprecated → @SuppressWarnings("deprecation") nit from the previous review has been addressed. No new issues introduced.

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

@gnodet

gnodet commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for this contribution — this is exactly the right problem to fix.

We've been discussing a broader classloader improvement plan for Maven 4.1 (tracked in #13223) and this PR is part of it. A few points from that discussion that affect how this should land:

compat/maven-embedder / MavenCli — please drop that change

MavenCli is deprecated and will be removed. The active CLI stack is impl/maven-cli / MavenCling (o.a.maven.cling). The 6-line change to MavenCli.java and the 159-line MavenCliExtensionClasspathTest should be removed — they're dead weight. The fix in PlexusContainerCapsuleFactory (already in this PR) is the right target.

Test should move to impl/maven-cli

PlexusContainerCapsuleFactoryTest is already there — great. But MavenCliExtensionClasspathTest in compat/maven-embedder should be dropped entirely (or the relevant test cases folded into PlexusContainerCapsuleFactoryTest).

Path deduplication

When multiple entries on maven.ext.class.path resolve to the same canonical path (symlinks, relative vs. absolute), we should deduplicate by toRealPath() before processing. Worth a quick check that the current implementation handles this.

Once those are addressed this looks mergeable as Layer 3 of the overall plan.

Drop the deprecated embedder changes and keep descriptor discovery in the active Maven CLI. Resolve classpath entries to real paths before processing while retaining the first spelling. Discover each descriptor independently so a malformed optional descriptor does not skip later valid exports. Cover relative and symlink aliases and malformed-first ordering.

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

Re-review after 00a67585: deduplication of maven.ext.class.path entries.

The toRealPath() + normalize() fallback correctly handles existing vs non-existent paths. The dedup gate fires on realPath while jars stores the original (uncanonicalised) path — that asymmetry is intentional and correct since ClassWorld doesn't care about path identity, only URL identity after addURL(file.toUri().toURL()).

The two new tests (processesEquivalentClassPathEntriesOnce, processesSymlinkedClassPathEntryOnce) are well-structured. The relative-path alias case correctly relies on context.cwd.resolve(alias) canonicalising back to the original absolute path before toRealPath().

Note for the record: MavenCli.parseExtClasspath() (compat layer) still lacks the equivalent deduplication. This is a pre-existing gap — the compat layer is deprecated, and the new commit is deliberately scoped to impl/maven-cli ("active CLI") — so it's not a blocker. Worth addressing separately if compat users report issues.

No new issues introduced.

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

@goutamadwant

Copy link
Copy Markdown
Contributor Author

Thanks @gnodet. I removed the deprecated MavenCli change and test, kept the fix in the active CLI, and deduplicated maven.ext.class.path by toRealPath() while retaining the first entry.

@gnodet gnodet added bug Something isn't working mvn4 enhancement New feature or request labels Oct 14, 2026
@gnodet
gnodet merged commit 60d9e49 into apache:master Nov 6, 2026
19 of 20 checks passed
@github-actions github-actions Bot added this to the 4.2.0 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request mvn4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MNG-8112] extension.xml is ignored when extension is loaded by -Dmaven.ext.class.path

3 participants