Skip to content

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

Closed

Description

@jira-importer

Rich DiCroce opened MNG-8112 and commented

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:

  1. 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()).
  2. 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.

If this is not a bug and is instead "works as designed", then https://maven.apache.org/guides/mini/guide-using-extensions.html needs to be updated to explain that the three methods of loading core extensions are not equivalent.


Affects: 3.9.6

Attachments:

Activity

  1. jira-importer commented on Jun 5, 2024

    @jira-importer
    Author

    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.

  2. jira-importer commented on Jun 26, 2024

    @jira-importer
    Author

    Guillaume Nodet commented

    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.

  3. jira-importer commented on Feb 22, 2025

    @jira-importer
    Author

    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.

  4. jira-importer commented on Feb 23, 2025

    @jira-importer
    Author

    Christoph Läubrich commented

    Same behavior / problem on ```
    Apache Maven 4.0.0-rc-2 (2733144)

    
    I use this in my ```
    META-INF/maven/extension.xml
    ```:
    
    

    <extension>
    <exportedPackages>
    <exportedPackage>org.codehaus.plexus.build</exportedPackage>
    </exportedPackages>
    <exportedArtifacts>
    <exportedArtifacts>org.codehaus.plexus:plexus-build-api</exportedArtifacts>
    </exportedArtifacts>
    </extension>

    
    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
    
  5. jira-importer commented on Feb 24, 2025

    @jira-importer
    Author

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

  6. jira-importer commented on Feb 24, 2025

    @jira-importer
    Author

    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.

  7. jira-importer commented on Feb 24, 2025

    @jira-importer
    Author

    Tamas Cservenak commented

    Sure, but this is not the point: point is WHY you'd configure both and expect one (to win)?

  8. jira-importer commented on Feb 24, 2025

    @jira-importer
    Author

    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

    • ${maven.home}/lib/ext --> Strongest, should override everything system wide
    • mvn -Dmaven.ext.class.path=extension.jar --> will override everything for the current run
    • .mvn/extensions.xml
    • project->build->plugins->plugin with element extensions=true

    Given that I declare ```
    <exportedArtifacts>org.codehaus.plexus:plexus-build-api</exportedArtifacts>

  9. jira-importer commented on Feb 24, 2025

    @jira-importer
    Author

    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.

  10. jira-importer commented on Feb 24, 2025

    @jira-importer
    Author

    Christoph Läubrich commented

    Good point. But this seem to not happen right now ...

  11. jira-importer commented on Feb 24, 2025

    @jira-importer
    Author

    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.

  12. added
    bug
    priority:major
    on Jul 7, 2025
  13. goutamadwant commented on Sep 13, 2026

    @goutamadwant
    Contributor

    @gnodet Fixed this in #13101 . Please take a look and let me know if you have any suggestions. Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority:major

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions