这是一个问题听起来像一堆类似的问题在SE的网站,所以我应该是相当冗长作出清楚我的问题。 所以,这里是项目的最小pom.xml
:
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.7</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.shabunc.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
下面是行家所产生的依赖关系树。
mvn dependency:tree -Dverbose -Dincludes=org.slf4j
:
[INFO] [dependency:tree {execution: default-cli}]
[INFO] org.shabunc:logdebug:jar:1.0-SNAPSHOT
[INFO] \- ch.qos.logback:logback-classic:jar:1.0.6:compile
[INFO] \- org.slf4j:slf4j-api:jar:1.6.5:compile
现在,让我们删除排除,并再次检查依赖性。 我们会得到:
[INFO] org.shabunc:logdebug:jar:1.0-SNAPSHOT
[INFO] +- ch.qos.logback:logback-classic:jar:1.0.6:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.6.5:compile
[INFO] \- org.codehaus.gmaven.runtime:gmaven-runtime-1.7:jar:1.3:compile
[INFO] +- (org.slf4j:slf4j-api:jar:1.5.10:compile - omitted for conflict with 1.6.5)
[INFO] +- org.codehaus.gmaven.feature:gmaven-feature-support:jar:1.3:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.5.10:compile - omitted for conflict with 1.6.5)
[INFO] \- org.codehaus.gmaven.runtime:gmaven-runtime-support:jar:1.3:compile
[INFO] +- (org.slf4j:slf4j-api:jar:1.5.10:compile - omitted for conflict with 1.6.5)
[INFO] \- org.sonatype.gshell:gshell-io:jar:2.0:compile
[INFO] \- org.sonatype.gossip:gossip:jar:1.0:compile
[INFO] \- (org.slf4j:slf4j-api:jar:1.5.8:compile - omitted for conflict with 1.6.5)
所以,我们可以看到,一切正常,而冲突的相关性实际上得到排除。 但事实是, 即使依赖排除我仍然可以在编译和调用以下消息mvn exec:java
:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/shabunc/.m2/repository/ch/qos/logback/logback-classic/1.0.6/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/shabunc/.m2/repository/org/sonatype/gossip/gossip/1.0/gossip-1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
现在的问题是:为什么我仍然看到此警告,究竟应该怎样做才能使执行过程中只有一个版本SLF4J到达的?