【发布时间】:2011-06-10 14:53:09
【问题描述】:
我正在尝试找到一种“通用”方式来排除传递依赖项,而不必将其从依赖它的所有依赖项中排除。例如,如果我想排除 slf4j,我执行以下操作:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jmx</artifactId>
<version>3.3.2.GA</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
<type>jar</type>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
这部分是为了清理 pom 文件,部分是为了避免将来人们添加依赖于排除的依赖项的依赖项而忘记排除它的问题。
有办法吗?
【问题讨论】:
-
不能解决问题,但是 maven-enforcer-plugin 有一个 banned dependencies feature,如果不需要的依赖项潜入,它将导致构建失败。但您仍然必须手动排除它们:-/
-
此处提供了替代答案:stackoverflow.com/a/39979760/363573
标签: maven maven-2 dependencies pom.xml