Skip to content

Commit 2d3ab2f

Browse files
committed
fix: SpotBugs needs 6.4.2 to run after JDK11, relax forbiddenApis on internal-api
Also this forces JDK 11 to be the minimum.
1 parent daf364f commit 2d3ab2f

File tree

4 files changed

+59
-43
lines changed

4 files changed

+59
-43
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ plugins {
55
id("datadog.dependency-locking")
66

77
id("com.diffplug.spotless") version "6.13.0"
8-
id("com.github.spotbugs") version "5.0.14"
8+
// id("com.github.spotbugs") version "5.0.14"
9+
id("com.github.spotbugs") version "6.4.2"
910
id("de.thetaphi.forbiddenapis") version "3.8"
1011

1112
id("tracer-version")

gradle/forbiddenapis.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ forbiddenApis {
3333
}
3434

3535
// disable forbiddenApis for all test tasks
36-
afterEvaluate {
37-
tasks.matching({it.name.startsWith('forbiddenApis') && it.name.endsWith('Test')}).configureEach {
38-
it.enabled = false
39-
}
36+
tasks.matching { it.name.startsWith('forbiddenApis') && it.name.endsWith('Test') }.configureEach {
37+
it.enabled = false
4038
}
4139

4240
dependencies {

gradle/spotbugs.gradle

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,55 @@ spotbugs {
66
}
77

88
// configure spotbugs for Main tasks and disable it for all other
9-
afterEvaluate {
10-
tasks.withType(spotbugsMain.class).configureEach {
11-
def name = it.name
12-
if (name.endsWith("Main") || name.endsWith("Main_java11")) {
13-
it.ignoreFailures = false
14-
// detector documentation is in the following link:
15-
// https://spotbugs-in-kengo-toda.readthedocs.io/en/lqc-list-detectors/detectors.html
16-
it.omitVisitors = [
17-
'DefaultEncodingDetector',
18-
'DoInsideDoPrivileged',
19-
'DontUseEnum',
20-
'DroppedException',
21-
'FindDeadLocalStores',
22-
'FindHEmismatch',
23-
'FindNullDeref',
24-
'FindReturnRef',
25-
'FindRunInvocations',
26-
'FindUselessControlFlow',
27-
'InitializationChain',
28-
'LazyInit',
29-
'LoadOfKnownNullValue',
30-
'LostLoggerDueToWeakReference',
31-
'MethodReturnCheck',
32-
'MutableStaticFields',
33-
'Naming',
34-
'RuntimeExceptionCapture',
35-
'SerializableIdiom',
36-
'UnreadFields',
37-
]
38-
it.reports {
39-
html {
40-
enabled = true
41-
destination = file("$buildDir/reports/spotbugs/${name}.html")
42-
stylesheet = 'fancy-hist.xsl'
43-
}
44-
}
45-
} else {
46-
it.enabled = false
9+
// Can't use the class here due to being different class
10+
tasks.matching { it.name.startsWith('spotbugs') }.configureEach {
11+
it.launcher = javaToolchains.launcherFor {
12+
it.languageVersion = JavaLanguageVersion.current()
13+
}
14+
15+
def launcher = it.launcher
16+
doFirst {
17+
println(launcher.get().executablePath)
18+
}
19+
20+
def name = it.name
21+
if (!(name.endsWith("Main") || name.endsWith("Main_java11"))) {
22+
it.enabled = false
23+
return
24+
}
25+
26+
it.showProgress = true
27+
it.ignoreFailures = false
28+
// detector documentation is in the following link:
29+
// https://spotbugs-in-kengo-toda.readthedocs.io/en/lqc-list-detectors/detectors.html
30+
it.omitVisitors = [
31+
'ConstructorThrow',
32+
'DefaultEncodingDetector',
33+
'DoInsideDoPrivileged',
34+
'DontUseEnum',
35+
'DroppedException',
36+
'FindDeadLocalStores',
37+
'FindHEmismatch',
38+
'FindNullDeref',
39+
'FindReturnRef',
40+
'FindRunInvocations',
41+
'FindUselessControlFlow',
42+
'InitializationChain',
43+
'LazyInit',
44+
'LoadOfKnownNullValue',
45+
'LostLoggerDueToWeakReference',
46+
'MethodReturnCheck',
47+
'MutableStaticFields',
48+
'Naming',
49+
'RuntimeExceptionCapture',
50+
'SerializableIdiom',
51+
'UnreadFields',
52+
]
53+
it.reports {
54+
html {
55+
required = true
56+
destination(file("$buildDir/reports/spotbugs/${name}.html"))
57+
stylesheet = 'fancy-hist.xsl'
4758
}
4859
}
4960
}

internal-api/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
12
import groovy.lang.Closure
23

34
plugins {
@@ -22,6 +23,11 @@ fun AbstractCompile.configureCompiler(javaVersionInteger: Int, compatibilityVers
2223
(project.extra["configureCompiler"] as Closure<*>).call(this, javaVersionInteger, compatibilityVersion, unsetReleaseFlagReason)
2324
}
2425

26+
tasks.named<CheckForbiddenApis>("forbiddenApisMain") {
27+
// sun.* are accessible in JDK8, but maybe not accessible when this task is running
28+
failOnMissingClasses = false
29+
}
30+
2531
val minimumBranchCoverage by extra(0.7)
2632
val minimumInstructionCoverage by extra(0.8)
2733

0 commit comments

Comments
 (0)