有没有办法,例如一个 Maven 插件,它可以获取不需要的/黑名单依赖项(直接和传递)的列表,如果它检测到列出的依赖项之一,则构建失败?
在我的项目中,我们非常希望摆脱 Apache Commons Logging 并将其替换为 SLF4J JCL Bridge。我知道我们必须自己排除不需要的依赖项,但如果有人添加了引入黑名单依赖项的依赖项,我希望构建失败。
最佳答案
您可以使用 maven-enforcer-plugin
禁止某些依赖项.
这是他们的示例,其中包含用于排除 Apache Commons Logging 的更新。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>commons-logging:commons-logging</exclude>
</excludes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
运行 mvn install
时的输出将是:
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.BannedDependencies failed with message:
Found Banned Dependency: commons-logging:commons-logging:jar:1.1.1
Use 'mvn dependency:tree' to locate the source of the banned dependencies.
一切都以BUILD FAILURE
结束。
关于java - 黑名单 Maven 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12794049/