我正在尝试找到一种“通用”的方法来排除传递依赖,而不必从依赖它的所有依赖中排除它。例如,如果我想排除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文件,部分是为了避免将来人们添加依赖于被排除的依赖关系-并忘记排除它-的问题。
有什么办法吗?
发布于 2011-01-18 03:31:09
这有帮助吗?http://jlorenzen.blogspot.com/2009/06/maven-global-excludes.html
“假设我想要从我的WAR中排除avalon-framework,我会将以下内容添加到我的项目POM中,范围为provided。这适用于所有可传递的依赖项,并允许您指定它一次。
<dependencies>
<dependency>
<artifactId>avalon-framework</artifactId>
<groupId>avalon-framework</groupId>
<version>4.1.3</version>
<scope>provided</scope>
</dependency>
</dependencies>这甚至适用于在父POM中指定它,这将避免项目必须在所有子POM中声明它。
发布于 2013-06-27 20:59:31
我创建了一个空jar,并创建了这个依赖:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<scope>system</scope>
<systemPath>${basedir}/src/lib/empty.jar</systemPath>
<version>0</version>
</dependency>它并不完美,因为从现在开始,您的编译/测试路径中有一个空的jar。但这只是表面上的。
发布于 2017-09-08 04:22:50
在dnault's comment上展开
可以使用Maven Enforcer plugin's Banned Dependencies rule来确保排除依赖项。仍然需要手动排除它们,但是如果有人错误地将依赖项添加到其他地方,构建将会失败。
<dependencies>
<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>
</dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>org.slf4j:slf4j-api</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>还有一个开放的功能请求:MNG-1977 Global dependency exclusions
https://stackoverflow.com/questions/4716310
复制相似问题