如何确保 Maven 依赖项在给定范围内?
How to make sure a maven dependency is in a given scope?
在我正在进行的项目中,我们发现我们的 EAR 使用 Oracle 一致性产品作为 compile
依赖项。这触发了已检测到的奇怪类路径问题,并且一致性现在是 provided
依赖项。
但是,我想确保没有人再犯直接或不直接使用连贯性作为 compile
的错误。那么,是否有任何 maven plugin/solution,在给定一组依赖约束的情况下,将确保所有 maven 模块都强制执行这些约束?
你应该深入了解 maven-enforcer-plugin 正是支持这些东西的。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>com.xyz:abc:*:jar:compile</exclude>
<exclude>com.xyz:abc:*:jar:runtime</exclude>
<exclude>com.xyz:abc:*:jar:test</exclude>
</excludes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
在我正在进行的项目中,我们发现我们的 EAR 使用 Oracle 一致性产品作为 compile
依赖项。这触发了已检测到的奇怪类路径问题,并且一致性现在是 provided
依赖项。
但是,我想确保没有人再犯直接或不直接使用连贯性作为 compile
的错误。那么,是否有任何 maven plugin/solution,在给定一组依赖约束的情况下,将确保所有 maven 模块都强制执行这些约束?
你应该深入了解 maven-enforcer-plugin 正是支持这些东西的。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>com.xyz:abc:*:jar:compile</exclude>
<exclude>com.xyz:abc:*:jar:runtime</exclude>
<exclude>com.xyz:abc:*:jar:test</exclude>
</excludes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>