Reputation: 51010
I want to exclude a direct dependency of a Maven plugin and the approach described in this answer does not work (as indicated by this comment).
As a particular example:
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.2</version>
<!-- more config -->
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.2</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
I still see javax.xml.bind:jaxb-api
in the list of dependencies (with mvn ... -X
). What am I doing wrong?
(In case someone has an idea for how to replace the dependency on that artifact with the JDK 9 equivalent for that API [as seems to happen on Java 8, where "JAXB API os loaded from the [jar:...jre/lib/rt.jar]"], I'm happy to open a new issue for that.)
Running out of ideas and this being an experiment anyways, I excluded the dependency by editing the plugin's pom.xml
in my local repository. Now mvn ... -X
shows that there is also an indirect dependency (in this case by org.jvnet.jaxb2.maven2:maven-jaxb22-plugin
) that I can successfully exclude with the mechanism above. Just using both excludes, from maven-jaxb2-plugin
and maven-jaxb22-plugin
, does not do the trick. This indicates that exclusion works in general but apparently not on a plugin's direct dependency.
(By the way, this indeed lead to "Java JAXB API is loaded from the [jrt:/java.xml.bind]", which was my goal.)
Upvotes: 26
Views: 13884
Reputation: 13
Check your dependency list with dependency:tree and solve whichever lib is introducing that lib dependency, then exclude it. Maybe your dependency couldn't be a direct one.
Just follow your dependency hierarchy
Upvotes: -2
Reputation: 12335
Up until now there hasn't been any reason to do this, but this seems like a valid one. Most clean solution I can think of is allowing to override the scope with "none" for plugin dependencies.
I've created MNG-6222 for it, not sure if we'll fix this for a Maven3, but it makes sense to do it at least for the next major.
Upvotes: 16
Reputation: 41220
I had a similar situation with maven-linkcheck-plugin
in the end I did a more brute force approach to remove the doxia-linkcheck
dependency and make it use my fork by forking maven-linkcheck-plugin
and creating my own with the proper dependencies.
Upvotes: 2