use*_*250 5 java maven-2 dependency-management maven
我将用我的实际情况解释这个问题。
我使用logback 1.0.1进行日志记录,它包括SLF4J 1.6.4作为依赖项。我还将SLF4J API桥用于旧式日志记录API(java.util.logging,log4j和commons-logging),它们不是显式的依赖项。这些还必须(最好是)版本1.6.4。
为了使我的pom.xml尽可能整洁且没有错误,我想强制要求这些API桥与SLF4J的版本相同。我知道的唯一方法是使用1.6.4版在我的pom.xml中手动将它们定义为依赖项。如果我更新了logback,并且提高了所需的SLF4J版本,则需要记住将网桥API更改为正确的版本。
我可以以某种方式将旧版API的版本与传递依赖项SLF4J的版本挂钩吗?
当前的pom.xml:
<properties>
<org.slf4j.version>1.6.4</org.slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.1</version>
<!-- requires SLF4J 1.6.4 -->
</dependency>
<!-- ... -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
<!-- here, how to bind this version value to SLF4J's version? -->
<scope>runtime</scope>
</dependency>
<!-- the other two bridge API's go here -->
</dependencies>
Run Code Online (Sandbox Code Playgroud)
不是以一种非常美丽的方式:/
有 Maven 执行器插件:http://maven.apache.org/enforcer/enforcer-rules/
因此您可以禁止传递依赖项并包含您想要的版本:http://maven.apache.org/enforcer/enforcer-rules/bannedDependency.html
如果您使用良好版本的属性,则无需在执行器插件版本中搞乱。