spotbugs / spotbugs-gradle-plugin

https://plugins.gradle.org/plugin/com.github.spotbugs
Apache License 2.0
179 stars 68 forks source link

SLF4j warnings during execution of spotbugsMain and spotbugsTest #676

Open rherrick opened 2 years ago

rherrick commented 2 years ago

This is the same issue as #133 and #136.

During execution of the spotbugsMain and spotbugsTest tasks, warnings appear from slf4j. I've attached spotbugs-gradle-issue-demo.zip with a sample project, but to demonstrate it locally, I've also provided a patch and script to generate a sample project independently. This requires Java 11 and the [Spring Boot CLI|https://docs.spring.io/spring-boot/docs/current/reference/html/cli.html] (alternatively you could generate the initial project on [Spring Initializr|https://start.spring.io]).

  1. Generate a Gradle project for Java 11
  2. Unzip the archive
  3. Apply the patch in build.gradle.txt
  4. Check the spotbugs configuration classpath
  5. Run the Gradle build with check

Here's the output from the build:

# ./gradlew clean check bootJar

> Task :spotbugsMain
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

> Task :spotbugsTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

BUILD SUCCESSFUL in 7s
9 actionable tasks: 9 executed

The cause is pretty apparent:

# ./gradlew dependencies --configuration spotbugs

> Task :dependencies

------------------------------------------------------------
Root project 'demo'
------------------------------------------------------------

spotbugs - configuration for the SpotBugs engine
\--- com.github.spotbugs:spotbugs:4.5.3
     +--- org.junit:junit-bom:5.8.2
     +--- jaxen:jaxen:1.2.0
     +--- net.sf.saxon:Saxon-HE:10.6
     +--- org.ow2.asm:asm:9.2
     +--- org.ow2.asm:asm-analysis:9.2
     |    \--- org.ow2.asm:asm-tree:9.2
     |         \--- org.ow2.asm:asm:9.2
     +--- org.ow2.asm:asm-commons:9.2
     |    +--- org.ow2.asm:asm:9.2
     |    +--- org.ow2.asm:asm-tree:9.2 (*)
     |    \--- org.ow2.asm:asm-analysis:9.2 (*)
     +--- org.ow2.asm:asm-tree:9.2 (*)
     +--- org.ow2.asm:asm-util:9.2
     |    +--- org.ow2.asm:asm:9.2
     |    +--- org.ow2.asm:asm-tree:9.2 (*)
     |    \--- org.ow2.asm:asm-analysis:9.2 (*)
     +--- org.apache.bcel:bcel:6.5.0
     +--- net.jcip:jcip-annotations:1.0
     +--- org.dom4j:dom4j:2.1.3
     +--- org.apache.commons:commons-lang3:3.12.0
     +--- org.apache.commons:commons-text:1.9
     |    \--- org.apache.commons:commons-lang3:3.11 -> 3.12.0
     +--- org.slf4j:slf4j-api:1.8.0-beta4 -> 1.7.33
     +--- com.github.spotbugs:spotbugs-annotations:4.5.3
     |    +--- org.junit:junit-bom:5.8.2
     |    \--- com.google.code.findbugs:jsr305:3.0.2
     \--- com.google.code.gson:gson:2.8.9

(*) - dependencies omitted (listed previously)

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 800ms
1 actionable task: 1 executed

I'm running on OS X 11.6.2 with Zulu Java 11.0.13, but replicated the issue on Ubuntu 20.04 with Zulu Java 11.0.14 as well. The script I ran contains:

spring init --build=gradle --java-version=11
mkdir demo
unzip demo.zip -d demo
cd demo
patch build.gradle ../build.gradle.txt
./gradlew dependencies --configuration spotbugs
./gradlew clean check bootJar

Please let me know if I can provide any other info on this issue.

MarcJose commented 2 years ago

You could try using

  spotbugsSlf4j group: 'org.slf4j', name: 'slf4j-api', version: '1.8.0-beta4'
  spotbugsSlf4j group: 'org.slf4j', name: 'slf4j-simple', version: '1.8.0-beta4'

as mentioned here

C-Otto commented 1 year ago

In my case the SLF4J version was changed because of Spring Boot. You can use ./gradlew project:dependencies --configuration spotbugsSl4fj to see the details. If the versions for the API and for the implementation differ (one is 2.x the other is 1.x), you might have the same problem. For me it helped to add the slf4j-simple dependency to the spotbugs task (with a version as determined by the rest of my setup, in this case Spring Boot): https://github.com/C-Otto/BitBook/commit/9c9a353b732153596d7b016ce8e71e76be91f008