SLF4J: multiple SLF4J bindings with Gradle Plugin
Asked Answered
M

1

13

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'
}
Moskowitz answered 2/8, 2018 at 2:46 Comment(3)
Did you ever find a solution to this?Vraisemblance
Doesn't fit the question as is, but for Googlers like me: you do not need plugin kotlin-dsl for using Gradle Kotlin DSL; remove it.Unpaidfor
@Unpaidfor Thank you. It really does deserve a separate question. You save my day(many days)Cas
P
6

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?

Preengage answered 14/11, 2019 at 11:43 Comment(1)
Tried this. Still the gradle jar sits in the boot jar. tasks.getting(BootJar::class) { exclude("gradle-api-.jar") exclude("'groovy-.jar") }Previse

© 2022 - 2024 — McMap. All rights reserved.