Skip to content

Commit ddaac8b

Browse files
authored
Add SpotBugs (#207)
1 parent 60b02d1 commit ddaac8b

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ dependencies {
1212
implementation("com.bmuschko:gradle-docker-plugin:9.4.0")
1313
implementation("gradle.plugin.com.google.gradle:osdetector-gradle-plugin:1.7.3")
1414
implementation("de.thetaphi:forbiddenapis:3.8")
15+
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:6.1.0")
1516
}

buildSrc/src/main/kotlin/sb-ot-demo.java-conventions.gradle.kts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
* Licensed under the Apache License 2.0
66
*/
77

8+
import com.github.spotbugs.snom.Confidence
9+
import com.github.spotbugs.snom.Effort
10+
import com.github.spotbugs.snom.SpotBugsTask
811
import net.ltgt.gradle.errorprone.errorprone
912

1013
plugins {
1114
id("java")
1215
id("jacoco")
1316
id("pmd")
1417
id("checkstyle")
18+
id("com.github.spotbugs")
1519
id("net.ltgt.errorprone")
1620
id("com.google.osdetector")
1721
}
@@ -31,6 +35,10 @@ dependencies {
3135

3236
errorprone("com.google.errorprone:error_prone_core:2.36.0")
3337
errorprone("jp.skypencil.errorprone.slf4j:errorprone-slf4j:0.1.28")
38+
39+
spotbugsPlugins("jp.skypencil.findbugs.slf4j:bug-pattern:1.5.0")
40+
spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.13.0")
41+
spotbugsPlugins("com.mebigfatguy.sb-contrib:sb-contrib:7.6.9")
3442
}
3543

3644
java {
@@ -58,6 +66,20 @@ pmd {
5866
ruleSets = listOf()
5967
}
6068

69+
spotbugs {
70+
showProgress.set(true)
71+
effort.set(Effort.MAX)
72+
reportLevel.set(Confidence.LOW)
73+
excludeFilter.set(file("${rootDir}/config/spotbugs/exclude.xml"))
74+
}
75+
76+
tasks.withType<SpotBugsTask>().configureEach {
77+
reports {
78+
create("xml") { enabled = true }
79+
create("html") { enabled = true }
80+
}
81+
}
82+
6183
tasks {
6284
withType<JavaCompile>().configureEach {
6385
options.compilerArgs.add("-parameters")
@@ -70,7 +92,7 @@ tasks {
7092

7193
test {
7294
useJUnitPlatform()
73-
dependsOn(checkstyleMain, checkstyleTest, pmdMain, pmdTest)
95+
dependsOn(checkstyleMain, checkstyleTest, pmdMain, pmdTest, spotbugsMain, spotbugsTest)
7496
finalizedBy(jacocoTestReport, jacocoTestCoverageVerification)
7597
maxParallelForks = 1
7698
}

config/spotbugs/exclude.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<FindBugsFilter>
3+
<Match>
4+
<Bug pattern="EI_EXPOSE_REP2,SLF4J_LOGGER_SHOULD_BE_NON_STATIC,IMC_IMMATURE_CLASS_NO_TOSTRING"/>
5+
</Match>
6+
<Match>
7+
<Bug pattern="SPRING_ENDPOINT,CRLF_INJECTION_LOGS,HTTP_RESPONSE_SPLITTING"/>
8+
</Match>
9+
<Match>
10+
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE,UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/>
11+
<Class name="~.*Test"/>
12+
</Match>
13+
</FindBugsFilter>

0 commit comments

Comments
 (0)