File tree 2 files changed +33
-1
lines changed
functionalTest/groovy/com/github/spotbugs/snom
main/groovy/com/github/spotbugs/snom
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -99,4 +99,28 @@ task spotbugsMain(type: com.github.spotbugs.snom.SpotBugsTask) {
99
99
result. task(" :classes" ). outcome == TaskOutcome . SUCCESS
100
100
result. task(" :spotbugsMain" ). outcome == TaskOutcome . SUCCESS
101
101
}
102
+
103
+ def " SpotBugsTask does not create report by default" () {
104
+ setup :
105
+ buildFile << """
106
+ task spotbugsMain(type: com.github.spotbugs.snom.SpotBugsTask) {
107
+ dependsOn 'classes'
108
+ classDirs = sourceSets.main.output
109
+ }
110
+ """
111
+ when :
112
+ BuildResult result =
113
+ GradleRunner . create()
114
+ .withProjectDir(rootDir)
115
+ .withArguments(" :spotbugsMain" )
116
+ .withPluginClasspath()
117
+ .forwardOutput()
118
+ .withGradleVersion(version)
119
+ .build()
120
+
121
+ then :
122
+ result. task(" :spotbugsMain" ). outcome == TaskOutcome . SUCCESS
123
+ File report = rootDir. toPath(). resolve(" build" ). resolve(" reports" ). resolve(" spotbugs" ). resolve(" main.xml" ). toFile()
124
+ ! report. isFile()
125
+ }
102
126
}
Original file line number Diff line number Diff line change @@ -363,7 +363,15 @@ class SpotBugsTask extends DefaultTask implements VerificationTask {
363
363
@Optional
364
364
@Nested
365
365
SpotBugsReport getFirstEnabledReport () {
366
- return reports. stream(). filter({report -> report. enabled}). findFirst(). orElse(null )
366
+ // use XML report by default, only when SpotBugs plugin is applied
367
+ boolean isSpotBugsPluingApplied = project. pluginManager. hasPlugin(" com.github.spotbugs" )
368
+
369
+ java.util.Optional<SpotBugsReport > report = reports. stream(). filter({ report -> report. enabled}). findFirst()
370
+ if (isSpotBugsPluingApplied) {
371
+ return report. orElse(reports. create(" xml" ))
372
+ } else {
373
+ return report. orElse(null )
374
+ }
367
375
}
368
376
369
377
void setReportLevel (@Nullable String name ) {
You can’t perform that action at this time.
0 commit comments