From f6a598a6e27f55f0d2979f3a8a0fab6fb4ff5954 Mon Sep 17 00:00:00 2001 From: soloturn Date: Sun, 23 Aug 2026 15:16:17 +0200 Subject: [PATCH] build: replace SpotBugs/FindBugs with Google Error Prone Swaps com.github.spotbugs (and the stale findbugs-exclude.xml config that predates the spotbugs migration) for net.ltgt.errorprone, which hooks static analysis directly into javac rather than running as a separate post-compile task. - build-logic/build.gradle.kts: drop spotbugs-gradle-plugin, add net.ltgt.gradle:gradle-errorprone-plugin. - terasology-metrics.gradle.kts: drop the spotbugs plugin/config/task wiring; apply net.ltgt.errorprone and configure it on every JavaCompile task. allErrorsAsWarnings is set to match this file's existing ignoreFailures = true posture on checkstyle/pmd - Error Prone's ERROR-severity checks otherwise fail the build outright, unlike the other analyzers configured here. - error_prone_core is pinned to 2.42.0, the last release that still runs on JDK 17 (2.43.0 raised Error Prone's own minimum JDK to 21, independent of this project's --release 17 compile target - the Jenkins agent's JDK isn't controlled from this repo, so this avoids silently requiring a CI bump as a side effect of this swap). - Jenkinsfile: recordIssues tool: findBugs(pattern: '**/build/reports/ findbugs/*.xml', ...) never actually matched spotbugs's real output path (**/build/reports/spotbugs/*.xml) - a pre-existing, unrelated mismatch. Error Prone has no separate XML report; it emits compiler warnings, which Jenkins' Warnings NG plugin has a purpose-built errorProne() console-log parser for. Replaced the findBugs() call with that. Verified end-to-end: :engine:compileJava, :desktop:compileJava, :engine:compileTestJava, and :modules:core:compileJava all build clean with Error Prone actively finding real issues (ClassNewInstance, CatchAndPrintStackTrace, StaticAssignmentInConstructor, etc.) as non-blocking warnings. :engine:checkstyleMain and :engine:pmdMain still run alongside it without interference. Stacked on #737 (the Kotlin DSL conversion) since terasology-metrics only exists as a .gradle.kts file on that branch. Co-Authored-By: Claude Sonnet 5 --- Jenkinsfile | 2 +- build-logic/build.gradle.kts | 2 +- .../main/kotlin/terasology-metrics.gradle.kts | 30 ++++++++----------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f38a484cb..83e5f063e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,7 +29,7 @@ pipeline { recordIssues tool: javaDoc() step([$class: 'JavadocArchiver', javadocDir: 'engine/build/docs/javadoc', keepAll: false]) recordIssues tool: checkStyle(pattern: '**/build/reports/checkstyle/*.xml') - recordIssues tool: findBugs(pattern: '**/build/reports/findbugs/*.xml', useRankAsPriority: true) + recordIssues tool: errorProne() recordIssues tool: pmdParser(pattern: '**/build/reports/pmd/*.xml') recordIssues tool: taskScanner(includePattern: '**/*.java,**/*.groovy,**/*.gradle', lowTags: 'WIBNIF', normalTags: 'TODO', highTags: 'ASAP') } diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index bf027c8e7..ab93b204c 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { implementation("com.google.code.gson:gson:2.10.1") - implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:5.2.3") + implementation("net.ltgt.gradle:gradle-errorprone-plugin:5.1.0") implementation("ru.vyarus:gradle-animalsniffer-plugin:2.0.1") implementation("de.undercouch:gradle-download-task:5.7.0") implementation("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.4.1") diff --git a/build-logic/src/main/kotlin/terasology-metrics.gradle.kts b/build-logic/src/main/kotlin/terasology-metrics.gradle.kts index 5f8d549d6..aad1c81d0 100644 --- a/build-logic/src/main/kotlin/terasology-metrics.gradle.kts +++ b/build-logic/src/main/kotlin/terasology-metrics.gradle.kts @@ -1,11 +1,11 @@ -import com.github.spotbugs.snom.SpotBugsTask +import net.ltgt.gradle.errorprone.errorprone plugins { java id("project-report") checkstyle pmd - id("com.github.spotbugs") + id("net.ltgt.errorprone") jacoco id("ru.vyarus.animalsniffer") } @@ -21,6 +21,11 @@ dependencies { "pmd"("net.sourceforge.pmd:pmd-java:7.26.0") "signature"("com.toasttab.android:gummy-bears-api-24:0.15.0:coreLib2@signature") + + // Pinned to the last release that still runs on JDK 17 (2.43.0+ requires JDK 21+ to run the + // analyzer itself, independent of this project's own --release 17 compile target) since the + // Jenkins CI agent's JDK version isn't controlled from this repo. + errorprone("com.google.errorprone:error_prone_core:2.42.0") } animalsniffer { @@ -57,15 +62,12 @@ pmd { ruleSets = listOf() } -spotbugs { - toolVersion.set("4.8.1") - ignoreFailures.set(true) - excludeFilter.set(File(rootDir, "config/metrics/findbugs/findbugs-exclude.xml")) -} -tasks.named("spotbugsMain") { - reports.create("xml") { - enabled = true - outputLocation.set(file("$buildDir/reports/spotbugs/main/spotbugs.xml")) +tasks.withType().configureEach { + options.errorprone { + // Match the ignoreFailures = true posture of checkstyle/pmd above: Error Prone's ERROR-severity + // checks fail the build by default, which none of the other analyzers here do. + allErrorsAsWarnings.set(true) + disableWarningsInGeneratedCode.set(true) } } @@ -76,7 +78,6 @@ val extractMetricsConfig = rootProject.tasks.findByName("extractMetricsConfig") into("$rootDir/config/metrics") }.get() -tasks.named("spotbugsMain") { dependsOn(extractMetricsConfig) } tasks.named("pmdMain") { dependsOn(extractMetricsConfig) } tasks.withType().configureEach { @@ -89,11 +90,6 @@ tasks.withType().configureEach { group = "Reporting" } -tasks.withType().configureEach { - dependsOn(extractMetricsConfig) - group = "Reporting" -} - tasks.check { dependsOn(extractMetricsConfig) }