【问题标题】:Gradle intelliJ plugin SLF4J: Class path contains multiple SLF4J bindingsGradle intelliJ 插件 SLF4J:类路径包含多个 SLF4J 绑定
【发布时间】:2020-06-07 06:46:28
【问题描述】:

我正在为 intelliJ IDEA 开发一个插件,并且我正在使用一个外部库。 当我运行时,我遇到了这个问题。

SLF4J:类路径包含多个 SLF4J 绑定。 SLF4J:在 [jar:file:/C:/Users/molos/Desktop/Thesis-folder/Thesis-project/build/idea-sandbox/plugins/Thesis-project/lib/slf4j-log4j12-1.6.0 中找到绑定。 jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J:在 [jar:file:/C:/Users/molos/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2019.3.1/52292e4f8a0ccb3ceb08bd81fd57b88923ac8e99/ideaIC-2019.3 中找到绑定.1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J:请参阅http://www.slf4j.org/codes.html#multiple_bindings 以获得解释。

这是我的 build.gradle。

plugins {
id 'java'
id 'maven-publish'
id 'org.jetbrains.intellij' version '0.4.10'
}

version '1.0-SNAPSHOT'

apply plugin: 'maven'

sourceCompatibility = 1.8

repositories {
   mavenCentral()
   maven {
      url = 'https://repo.maven.apache.org/maven2'
}


dependencies {
  // https://mvnrepository.com/artifact/com.github.mauricioaniche/ck
compile group: 'com.github.mauricioaniche', name: 'ck', version: '0.4.4'
// https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit
compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '2.2.0.201212191850-r'
// https://mvnrepository.com/artifact/org.apache.commons/commons-csv
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.1'



}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2019.3.1'
}

我尝试了我找到的许多解决方案,但我无法解决。

有人可以帮我吗?

【问题讨论】:

  • 您是否尝试过清除 m2 文件夹并重新安装您的依赖项?如果你这样做了但仍然发现同样的问题,那么有一些依赖项正在下载 SLF4J 作为横向依赖项,如果你可以发布你的 pom.xml 文件,可能我或其他人可以帮助你。
  • 我试图清理 m2 文件夹和其他想法文件夹。我用 build.gradle 编辑帖子
  • 我会尝试从其他依赖项中搜索 slf4j 依赖项。您应该将它从其他依赖项中排除,然后自己在 build.gradle 中添加一个。我推荐的另一件事是使用 force 命令。看这里docs.gradle.org/current/dsl/…
  • 我以为它是 maven 构建...我的坏事没有必要清除 .m2 尝试 clearing gradle cache

标签: java gradle intellij-idea slf4j intellij-plugin


【解决方案1】:

我可以通过在我的 build.gradle.kts 文件中排除 slf4j-api 依赖项来解决这个问题。

dependencies {
    detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.17.1")

    // JGIT
     implementation(group="org.eclipse.jgit", name="org.eclipse.jgit", version="5.11.1.202105131744-r"){
           exclude(group="org.slf4j", module="slf4j-api")
     }

}

【讨论】:

    【解决方案2】:

    我在最近使用 Gradle 6.7 和 Spring Boot 2.3.4.RELEASE 的应用程序中遇到了同样的问题。我最终排除了 IntelliJ 插件引入的内容以及其他一些内容。

    plugins {
        id 'java'
        id 'org.jetbrains.intellij' version '0.5.1'
        id 'org.springframework.boot' version '2.3.4.RELEASE'
        id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    }
    ...
    configurations {
        // the ideaIC module is adding the slf4j-log4j12 module and StaticLoggerBinder.class
        implementation.exclude(group: 'com.jetbrains', module: 'ideaIC')
        
        // the groovy plugin was adding groovy to the runtime
        implementation.exclude(group: 'org.codehaus.groovy', module: 'groovy-all')
    
        // spring-boot-logging brought in logback and log4j-to-slf4j which I don't want
        //   since I am using org.springframework.boot:spring-boot-starter-log4j2
        compile.exclude(group: 'ch.qos.logback')
        compile.exclude(group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j')
    }
    

    这是一种蛮力,但它有效。也许 Gradle 文件中缺少某些设置,导致添加了这些不必要的模块。我当然不希望这些插件将这些东西添加到我的 JAR 中。

    【讨论】:

      猜你喜欢
      • 2019-08-01
      • 2012-12-11
      • 2016-03-12
      • 2014-05-18
      • 2021-05-19
      • 2020-07-07
      • 1970-01-01
      • 2018-12-12
      • 2012-09-11
      相关资源
      最近更新 更多