如何排除Maven插件的直接依赖关系 [英] How to exclude a direct dependency of a Maven Plugin
问题描述
我想排除Maven插件的直接依赖关系,此答案中描述的方法不起作用(如由此评论表示。
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).
作为一个特例:
<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>
我仍然看到 javax.xml.bind:jaxb-api $依赖项列表中的c $ c>(
mvn ... -X
)。我做错了什么?
I still see javax.xml.bind:jaxb-api
in the list of dependencies (with mvn ... -X
). What am I doing wrong?
(如果有人知道如何用该API的JDK 9等效替换该工件的依赖关系[似乎发生了]在Java 8上,JAXB API os从[jar:... jre / lib / rt.jar]加载,我很高兴为此开启一个新问题。)
(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.)
无论如何都没有想法,我通过编辑插件的 pom排除了依赖关系。我本地存储库中的xml
。现在 mvn ... -X
表明还存在间接依赖关系(在本例中为 org.jvnet.jaxb2.maven2:maven-jaxb22 -plugin
)我可以使用上面的机制成功排除。只使用两个排除,从 maven-jaxb2-plugin
和 maven-jaxb22-plugin
,不能解决问题。这表明排除通常有效,但显然不是插件的直接依赖。
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.
(顺便说一句,这确实导致Java JAXB API从[jrt]加载:/java.xml.bind],这是我的目标。)
(By the way, this indeed lead to "Java JAXB API is loaded from the [jrt:/java.xml.bind]", which was my goal.)
推荐答案
到目前为止还没有任何这样做的原因,但这似乎是一个有效的。我能想到的最干净的解决方案是允许用插件依赖性的无覆盖范围。
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.
我创建了 MNG-6222 ,不知道我们是否会为Maven3解决这个问题,但至少做到这一点是有意义的为下一个专业。
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.
这篇关于如何排除Maven插件的直接依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!