简体   繁体   English

如何从 Gradle 中的依赖项中排除内部 package(不是 maven 依赖项)

[英]How to exclude internal package (not maven dependency) from dependcies in Gradle

My project is a spring boot project and it has a dependency which is dexkiller , however the dexkiller rely on soot-infoflow-cmd-jar-with-dependencies which internally uses slf4j while my spring boot project used slf4j as well.我的项目是 spring 启动项目,它有一个依赖dexkiller ,但是 dexkiller 依赖于内部使用 slf4j soot-infoflow-cmd-jar-with-dependencies而我的 spring 启动项目也使用 slf4j。
Thus making the following error when I run up my project.因此,当我运行我的项目时会出现以下错误。
The error is:错误是:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/user/.gradle/caches/modules-2/files-2.1/de.tud.sse/soot-infoflow-cmd-jar-with-dependencies/1.0/75ee1aee22aee20d41153e43b16b874caa927d2c/soot-infoflow-cmd-jar-with-dependencies-1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/user/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.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.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory loaded from file:/Users/user/.gradle/caches/modules-2/files-2.1/de.tud.sse/soot-infoflow-cmd-jar-with-dependencies/1.0/75ee1aee22aee20d41153e43b16b874caa927d2c/soot-infoflow-cmd-jar-with-dependencies-1.0.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.SimpleLoggerFactory
    at org.springframework.util.Assert.instanceCheckFailed(Assert.java:655)
    at org.springframework.util.Assert.isInstanceOf(Assert.java:555)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:280)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:104)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:219)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:200)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:70)
    at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)

The dependency tree is like below(soot* jars from my nexus repo):依赖关系树如下(soot* jars from my nexus repo):

+--- com.mywork:dexkiller:1.3.1-SNAPSHOT
|    +--- commons-collections:commons-collections:3.2
|    +--- cde.tud.sse:soot-infoflow-cmd-jar-with-dependencies:2.7
|    \--- cde.tud.sse:soot-infoflow-summaries-classes:2.7

Extracted files from soot-infoflow-cmd-jar-with-dependencies.jar从 soot-infoflow-cmd-jar-with-dependencies.jar 中提取的文件

提取的文件

I've tried to exclude the slf4j from dexkiller, but not work.我试图从 dexkiller 中排除 slf4j,但不起作用。

dependencies {
    compile ('com.mywork:dexkiller:1.3.1-SNAPSHOT'){
            // tried both them and each of them, neither work
            exclude group:'org.slf4j'
            exclude group:'org.apache.logging.log4j', module:'log4j-slf4j-impl'
    }
}

also this way也是这样

configurations.all {
    // tried both them and each of them, neither work
    exclude group: 'org.slf4j', module: 'dexkiller'
    exclude group:'org.apache.logging.log4j', module:'log4j-slf4j-impl'
}

Someone told me try有人告诉我试试

configurations {
    compile.exclude module: 'spring-boot-starter-logging'
}

It just avoided the multiple SLF4J bindings conflicts, but I'd like use my slf4j not the slf4j from soot jars.它只是避免了多个 SLF4J 绑定冲突,但我想使用我的 slf4j 而不是来自 soot jars 的 slf4j。

A jar-with-dependencies should not be used as dependency.一个jar-with-dependencies不应用作依赖项。 If you have any influence on that, correct that.如果你对此有任何影响,请纠正它。 Otherwise you might try to exclude the whole jar with dependencies and add the included dependencies one-by-one again until your project works.否则,您可能会尝试使用依赖项排除整个 jar 并再次逐一添加包含的依赖项,直到您的项目正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Gradle 依赖中排除包 - Exclude Package From Gradle Dependency 如何使用maven程序集插件从依赖jar中排除一个包? - How to use maven assembly plugin to exclude a package from dependency jar? 从Maven依赖项(webjars)中排除资源包 - Exclude resource package from maven dependency (webjars) 如何使用Maven捆绑插件(BND)将命名包从另一个依赖关系中存在的依赖关系中排除? - How to exclude a named package from a dependency that exists in another dependency using Maven Bundle Plugin (BND)? Gradle:如何从JScience jar依赖项中排除javax.realtime包(Multiple dex define) - Gradle: How to exclude javax.realtime package from JScience jar dependency (Multiple dex define) Gradle:如何从jar中排除特定包? - Gradle: How to exclude a particular package from a jar? 如何从不是用Maven构建的jar中将类作为Maven依赖项排除在外? - How to exclude a class as a maven dependency from a jar that is not built with maven? 如何在运行时从 Maven 依赖项(Jar 依赖项)中排除特定类 - How to exclude specific class from a Maven dependency ( Jar dependency) at runtime 如何从罐子中排除包装(使用Maven) - How to exclude a package from a jar (with maven) 在Maven中从依赖项中排除文件夹 - Exclude folder from dependency in maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM