saw*_*303 17 java maven-3 maven
有没有一种方法,例如Maven插件,可以列出不需要的/黑色列出的依赖项(直接和传递),如果它检测到列出的依赖项之一,则无法构建?
在我的项目中,我们严格要求摆脱Apache Commons Logging并将其替换为SLF4J JCL Bridge.我知道我们必须排除不需要的deps自己,但如果有人添加一个带来黑名单依赖的依赖项,我想让构建失败.
mab*_*aba 20
你可以使用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>
Run Code Online (Sandbox Code Playgroud)
运行时的输出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.
Run Code Online (Sandbox Code Playgroud)
这一切都以一个结束BUILD FAILURE.
| 归档时间: |
|
| 查看次数: |
8126 次 |
| 最近记录: |