SLF4J: multiple SLF4J bindings with Gradle Plugin

2020-07-10 02:49发布

问题:

I know its a common issue to have the issue with SLF4J: Class path contains multiple SLF4J bindings.

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]

I'm getting this error when I run a gradle build and I have applied the gradle-plugin plugin e.g. class with

import org.gradle.api.*
class CommonTestPlugin implements Plugin<Project> {

and in gradle

apply plugin: 'java-gradle-plugin'  

I'm using that plugin so I can add code to create a plugin.

The error above seems to point to gradle-api as the offending dependency but I when I fired up the dependency-insight task with dependencyInsight --dependency gradle-api

it returned:

No dependencies matching given input were found in configuration ':compileClasspath'

My question is: how can I determine how to define/exclude dependency that the plugin is using? Im using things like the following, I just can't figure out how to apply that to the plugin-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'
}

回答1:

I've hit the same problem. The workaround I've found so far is a brutal exclusion from the target JAR being built:

bootJar{
  exclude('gradle-api-*.jar', 'groovy-*.jar')
}

I'm using Spring boot plugin. bootJar extends jar task.

The question remains, though: do all the users of a plugin must do this kind of exclusion hocus-pocus in order to get it to work?