排除单个依赖项的所有传递依赖项 [英] Exclude all transitive dependencies of a single dependency

查看:98
本文介绍了排除单个依赖项的所有传递依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Maven2中,要排除单个传递依赖项,我必须执行以下操作:

In Maven2, to exclude a single transitive dependency, I have to do something like this:

<dependency>
  <groupId>sample.group</groupId>
  <artifactId>sample-artifactB</artifactId>
  <version>1</version>
   <exclusions>
     <exclusion>
       <groupId>sample.group</groupId>
       <artifactId>sample-artifactAB</artifactId>
     </exclusion>
   </exclusions>
</dependency>

此方法的问题在于,我必须对sample-artifactB贡献的每个传递依赖项都执行此操作.

The problem with this approach is that I have to do this for every transitive dependency contributed by sample-artifactB.

有没有办法使用某种通配符一次而不是一个接一个地排除所有传递依赖项?

Is there a way to use some sort of wildcard to exclude all transitive dependencies at once instead of one-by-one?

推荐答案

对于maven2,没有一种方法可以做您描述的事情.对于Maven 3,有.如果您使用的是Maven 3,请参见此问题的另一个答案

For maven2 there isn't a way to do what you describe. For maven 3, there is. If you are using maven 3 please see another answer for this question

对于Maven 2,我建议您为具有< exclusions>的依赖项创建自己的自定义pom.对于需要使用该依赖项的项目,请将依赖项设置为自定义pom而不是典型的工件.虽然并不一定允许您使用单个< exclusion>排除所有可传递依赖项,但确实允许您只需编写一次依赖项,并且所有项目都不需要维护不必要且冗长的排除项列表.

For maven 2 I'd recommend creating your own custom pom for the dependency that has your <exclusions>. For projects that need to use that dependency, set the dependency to your custom pom instead of the typical artifact. While that does not necessarily allow you exclude all transitive dependencies with a single <exclusion>, it does allow you only have to write your dependency once and all of your projects don't need to maintain unnecessary and long exclusion lists.

这篇关于排除单个依赖项的所有传递依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆