Java 排除maven中的依赖项

Java 排除maven中的依赖项,java,maven,slf4j,maven-shade-plugin,Java,Maven,Slf4j,Maven Shade Plugin,我的项目中存在相互冲突的依赖项问题。特别是,有两种slf4j日志记录的实现:slf4j simple和logback classic SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/Users/apykhtin/.m2/repository/org/slf4j/slf4j-simple/1.7.19/slf4j-simple-1.7.19.jar!/org/slf4j/i

我的项目中存在相互冲突的依赖项问题。特别是,有两种slf4j日志记录的实现:slf4j simple和logback classic

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/apykhtin/.m2/repository/org/slf4j/slf4j-simple/1.7.19/slf4j-simple-1.7.19.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/apykhtin/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
Exception in thread "main" java.lang.IllegalStateException: Unable to acquire the logger context
        at io.dropwizard.logging.LoggingUtil.getLoggerContext(LoggingUtil.java:46)
在运行时

logback classic对我来说是一个必须的依赖项(因为dropwizard),但slf4j并不简单,我想从我的uber项目中删除它。只是没那么容易

我的“uber jar”依赖于“small jar”,而“small jar”又依赖于“slf4j simple”。在uber jar的pom中加入排除项无助于:

<dependency>
    <groupId>com.my.unique.group</groupId>
    <artifactId>small-jar</artifactId>
    <version>0.1.2-SNAPSHOT</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </exclusion>
    </exclusions>
</dependency>

com.my.unique.group
小罐子
0.1.2-快照
org.slf4j
slf4j简单
我想是因为小罐子有阴影。我的“uber jar”使用的是maven shade插件,而“small jar”则不是。 我还尝试从着色中排除slf4j simple:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.6</version>
    <configuration>
    <artifactSet>
        <excludes>
            <exclude>org.slf4j:slf4j-simple:jar</exclude>
        </excludes>
    </artifactSet>
    ...
</plugin>

org.apache.maven.plugins
maven阴影插件
1.6
org.slf4j:slf4j简单:jar
...
但也没有成功。slf4j simple仍然包含在我的uber jar中。 到目前为止,我的开发都与“优步jar”有关。我可以对“小jar”代码进行更改,但我希望避免这样做


我做错了什么?

我不知道你说的“优步罐子”是什么意思。父项目

任何方法都可以使用
mvn dependency:tree-Dincludes=:slf4j*
查看它的来源,然后在较低的项目中定义依赖项,并像上面所做的那样排除传递项


希望这有帮助

为什么小罐子被遮住了?在将小jar编译为非着色工件时,似乎可以让maven处理slf4j的可传递依赖关系,然后在“uber jar”中依赖小jar时,排除必要的可传递依赖关系(即slf4j)。一旦着色,maven将无法排除依赖项,因为据它所知,小罐子中的所有内容都是单个依赖项


我知道您希望避免对小jar进行更改,但这通常是着色的固有问题之一。我建议不要给小jar着色,或者至少从小jar着色中排除slf4j,让maven将其作为一个正常的可传递依赖项处理,可以在uber jar的依赖项配置中排除

谢谢,希沙姆。我所说的“优步jar”是指我的大师级项目。奇怪的是,slf4j simple不在maven依赖树中,但无论如何它都会进入主jar。到目前为止(根据maven的构建消息),我能够从着色中排除小jar。然而,这并没有阻止uber jar引入slf4j simple,即使它被明确列为依赖项排除项。小jar是uber jar唯一的依赖项吗?有可能是另一个依赖项带来了它,您需要全局排除它。值得检查,但不,其他项目没有带来slf4j-simple。更新:maven shade插件不是罪魁祸首。我完全关闭了这个插件,仍然得到完全相同的错误。更新2:显然我的问题是由项目配置错误引起的。在清除所有内容(包括maven存储库)、签出新的源代码并从头开始在Eclipse中创建项目之后,所有内容都按预期工作。谢谢大家。