我知道 SLF4J 的问题是一个常见问题:类路径包含多个 SLF4J 绑定(bind)。
SLF4J: Found binding in [jar:file:/C:/Users/<name>/.gradle/caches/4.9/generated-gradle-jars/gradle-api-4.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/<name>/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.2/afd596adf5086b4f4746254b25a3a4b513f1d6e4/log4j-slf4j-impl-2.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
运行 gradle build 并应用了 gradle-plugin 插件时出现此错误
例如类与
import org.gradle.api.*
class CommonTestPlugin implements Plugin<Project> {
并在 gradle
apply plugin: 'java-gradle-plugin'
我正在使用该插件,因此我可以添加代码来创建插件。
上面的错误似乎指向 gradle-api 作为有问题的依赖项,但是当我启动依赖项洞察任务时
dependencyInsight -- 依赖 gradle-api
它返回:
No dependencies matching given input were found in configuration ':compileClasspath'
我的问题是:如何确定如何定义/排除插件正在使用的依赖项?我使用类似以下的东西,我只是不知道如何将它应用到插件 API
compile (group: 'com.aestasit.infrastructure.sshoogr', name: 'sshoogr', version: '0.9.26'){
// exclude this to stop warnings about multiple SLF4J bindings.
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
最佳答案
我遇到了同样的问题。到目前为止,我发现的解决方法是从正在构建的目标 JAR 中粗暴地排除:
bootJar{
exclude('gradle-api-*.jar', 'groovy-*.jar')
}
我正在使用 Spring Boot 插件。
bootJar
扩展 jar
任务。但是,问题仍然存在:插件的所有用户是否都必须进行这种排除恶作剧才能使其正常工作?
关于gradle - SLF4J : multiple SLF4J bindings with Gradle Plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51644795/