我会用我的真实情况来解释这个问题。Maven 2 - 从传递依赖版本定义依赖版本
我使用logback 1.0.1进行日志记录,它包含SLF4J 1.6.4作为依赖项。我还为传统日志记录API(java.util.logging,log4j和commons-logging)使用SLF4J API网桥,这些网桥不是显式依赖关系。这些也必须(最好)是版本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>
我看着执行者,但它不是我真正需要的东西。如果我简单地在我的pom中定义SLF4J,我会得到相同的结果。它可以正常工作,但是不会通过logback升级“自动”,我还需要更改SLF4J版本。功能,但不是一个美丽的方式...... ;-) – user1183250 2013-02-14 11:18:16
jepp!事情是这并不妨碍人们通过直接添加它们来改变传递依赖的版本。如果你禁止那些你确定没有人能够做到这一点。但这可能不是问题:) – wemu 2013-02-14 12:17:15