You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MNG-8112] extension.xml is ignored when extension is loaded by -Dmaven.ext.class.path #10506
As the title says: extension.xml is ignored when an extension is loaded by -Dmaven.ext.class.path, which makes it impossible to expose any additional packages.
I am filing this as a bug due to this comment on MNG-6906, which says that lib/ext and -Dmaven.ext.class.path are supposed to be synonymous. Note that MNG-6906 is a related but different problem.
When looking at org.apache.maven.cli.MavenCli, the problems aren't too hard to see:
lib/ext extensions get loaded into the plexus.core realm (as per m2.conf), but -Dmaven.ext.class.path extensions are loaded into the maven.ext realm (as per MavenCli#setupContainerRealm()).
loadCoreExtensions() operates on the coreRealm, but due to [MNG-5445] Fix missing requirement in AbstractStringBasedModelInterpolator #1, the extensions are not in that realm. Also, the result of parseExtClasspath() is not passed to loadCoreExtensions(), so there is no way for loadCoreExtensions() to find the relevant files.
The most obvious solution would be to call coreRealm.addURL() for each of the files discovered by parseExtClasspath(). This would solve #1 above which would implicitly fix #2. Though I don't know if it would have other consequences.
-This is by design: this file resolves and adds to classpath. ext class path means is already on classpath.- Sorry, I mixed up extension.xml and extensions.xml, ignore this.
I don't think so. If the ext classpath contains extensions configured using META-INF/maven/extension.xml, I don't really see any good reason why they would not be parsed and managed.
Can someone give a hint what has to be changed here? I also hit this problem and it looks that if the jar version match 1:1 (the one of the mojo and the one of the extension) then it actually works but this is of course not guaranteed.
When the plugin is added with ```
.mvn/extensions.xml
```then it is replaced on other mojos and I got this print out:
> [INFO] [stdout] Event listener created by ClassRealm[coreExtension>org.codehaus.plexus:plexus-build-api:1.2.1-SNAPSHOT, parent: ClassRealm[plexus.core, parent: null]]
When I use instead ```
-Dmaven.ext.class.path=...
``` then it is not replaced in classpath of mojos and I get
> [INFO] [stdout] Event listener created by ClassRealm[maven.ext, parent: ClassRealm[plexus.core, parent: null]]
If I use both (```
.mvn/extensions.xml
``` and
```-Dmaven.ext.class.path=...
```) then I get it two times:
> [INFO] [stdout] Event listener created by ClassRealm[coreExtension>org.codehaus.plexus:plexus-build-api:1.2.1-SNAPSHOT, parent: ClassRealm[plexus.core, parent: null]]
> [INFO] [stdout] Event listener created by ClassRealm[coreExtension>org.codehaus.plexus:plexus-build-api:1.2.1-SNAPSHOT, parent: ClassRealm[plexus.core, parent: null]]
My expectation would be:
1. It replaces the jar in the mojos classpath regardless of what technique is used
1. If it is used in multiple places then ```
-Dmaven.ext.class.path=...
``` takes precedence over
```.mvn/extensions.xml
Just to explain "last" bit ("My expectation would be"): This cannot happen (easily), as there is nothing to compare the two, the -Dmaven.ext.class.path=... is a path, and the JARs (files) on it are "lumped" onto maven.ext classpath (created IF extensions exist in system), while the .mvn/extensions.xml identifies the extension by GAV and create separate classloaders for each entry that maven.ext classloader "aggregates". So what happens if:
ONE of the file on ext.class.path (out of possibly many) is same as one GAV in extensions.xml? Also, what "same" means? How to check for "same"? Does version count? File hashes? Java packages conflict?
as can be seen, they end up in DIFFERENT CLASSLOADERS, as maven.ext directly loads former ones, and imports latter ones (as they get each own classloader).
Perso, I just think this expectation is wrong (again, this is ONLY about last "my expectation" thing, not about this issue as whole or the rest of things mentioned here).
If I look at my jar, it has the following structure
!image-2025-02-24-13-07-19-735.png!
so maven can learn (and many tools do so) the GAV of a plain jar, of course this is optional information, but if it is provided I think it can be used quite easy.
I don't think Maven needs to know which jar corresponds to a given exported artifact. It's used to filter out those artifacts from the dependency tree of plugins, that's all. So you could flag as exported an artifact which is not in the class path, that's not really a problem.
Activity
jira-importer commentedon Jun 5, 2024
Tamas Cservenak commented
-This is by design: this file resolves and adds to classpath. ext class path means is already on classpath.- Sorry, I mixed up extension.xml and extensions.xml, ignore this.
jira-importer commentedon Jun 26, 2024
Guillaume Nodet commented
I don't think so. If the
extclasspath contains extensions configured usingMETA-INF/maven/extension.xml, I don't really see any good reason why they would not be parsed and managed.jira-importer commentedon Feb 22, 2025
Christoph Läubrich commented
Can someone give a hint what has to be changed here? I also hit this problem and it looks that if the jar version match 1:1 (the one of the mojo and the one of the extension) then it actually works but this is of course not guaranteed.
jira-importer commentedon Feb 23, 2025
Christoph Läubrich commented
Same behavior / problem on ```
Apache Maven 4.0.0-rc-2 (2733144)
<extension>
<exportedPackages>
<exportedPackage>org.codehaus.plexus.build</exportedPackage>
</exportedPackages>
<exportedArtifacts>
<exportedArtifacts>org.codehaus.plexus:plexus-build-api</exportedArtifacts>
</exportedArtifacts>
</extension>
jira-importer commentedon Feb 24, 2025
Tamas Cservenak commented
Just to explain "last" bit ("My expectation would be"): This cannot happen (easily), as there is nothing to compare the two, the
-Dmaven.ext.class.path=...is a path, and the JARs (files) on it are "lumped" onto maven.ext classpath (created IF extensions exist in system), while the.mvn/extensions.xmlidentifies the extension by GAV and create separate classloaders for each entry that maven.ext classloader "aggregates". So what happens if:Perso, I just think this expectation is wrong (again, this is ONLY about last "my expectation" thing, not about this issue as whole or the rest of things mentioned here).
jira-importer commentedon Feb 24, 2025
Christoph Läubrich commented
If I look at my jar, it has the following structure
!image-2025-02-24-13-07-19-735.png!
so maven can learn (and many tools do so) the GAV of a plain jar, of course this is optional information, but if it is provided I think it can be used quite easy.
jira-importer commentedon Feb 24, 2025
Tamas Cservenak commented
Sure, but this is not the point: point is WHY you'd configure both and expect one (to win)?
jira-importer commentedon Feb 24, 2025
Christoph Läubrich commented
Of course I did it here for demonstration purpose. In the end one can know what people really do.
From https://maven.apache.org/guides/mini/guide-using-extensions.html there is some kind of ordering
Given that I declare ```
<exportedArtifacts>org.codehaus.plexus:plexus-build-api</exportedArtifacts>
jira-importer commentedon Feb 24, 2025
Guillaume Nodet commented
I don't think Maven needs to know which jar corresponds to a given exported artifact. It's used to filter out those artifacts from the dependency tree of plugins, that's all. So you could flag as exported an artifact which is not in the class path, that's not really a problem.
jira-importer commentedon Feb 24, 2025
Christoph Läubrich commented
Good point. But this seem to not happen right now ...
jira-importer commentedon Feb 24, 2025
Rich DiCroce commented
IMO https://maven.apache.org/guides/mini/guide-using-extensions.html does not imply any ordering, and that is not what this issue is about anyway. I opened this issue because extensions are not loaded correctly when you try to load them via -Dmaven.ext.class.path. Any other problem should be moved to a separate Jira issue.
goutamadwant commentedon Sep 13, 2026
@gnodet Fixed this in #13101 . Please take a look and let me know if you have any suggestions. Thanks!