Open booniepepper opened 4 years ago
spotbugsTest.enabled = false
is what I use
Unfortunately, that doesn't prevent the task from being created and the check
task depending on it. So even if you use spotbugsTest.enabled = false
, it will run compileTestGroovy
for example.
Unfortunately, that doesn't prevent the task from being created and the
check
task depending on it. So even if you usespotbugsTest.enabled = false
, it will runcompileTestGroovy
for example.
Seems like a bug in gradle then, because if a task is disabled it shouldn't run tasks that it depends on.
Sounds reasonable.
So, it seems that, as long as we cannot choose the source sets for which the tasks are created, the best way to prevent the spotbugsTest (and its dependencies) from running is to do exactly that by specifying -x spotbugsTest
on the command line.
This works for me to disable spotbugsTest
in build.gradle
:
// kotlin dsl
tasks {
spotbugsTest {
onlyIf { false }
}
}
gradle reports it as
> Task :spotbugsTest SKIPPED
A little late to the party, but
spotbugs<SourceSetName> {
enabled = false;
}
works for any source set.
Example:
sourceSets {
benchmarks {
java {}
}
}
spotbugsBenchmarks {
enabled = false
}
My preferred solution (from this StackOverflow answer) is:
project.gradle.startParameter.excludedTaskNames.add(":spotbugsTest")
I have this configuration in tasks { }
, directly adjacent to my spotbugsMain
task configuration. E.g.:
tasks {
// ...
// spotbugs-gradle-plugin creates a :spotbugsTest task by default, but we don't want it
// see: https://github.com/spotbugs/spotbugs-gradle-plugin/issues/391
project.gradle.startParameter.excludedTaskNames.add(":spotbugsTest")
spotbugsMain {
baselineFile.set(file("$rootDir/config/spotbugs/baseline.xml"))
reports.create("html") {
required.set(true)
}
}
// ...
}
I prefer this to skipping the task, as now :spotbugsTest
no longer shows up when I'm doing task listing or analysis.
I own a Gradle plugin at my company (Amazon) that's kind of an "aggregate" plugin for quality defaults. It gets used by a lot of engineering teams.
I think it makes sense as a default to run spotbugs against source code and test code (and really any code) but sometimes developers don't want to run spotbugs against their test code. Especially if they're vending libraries that do arcane and fiddly things where they will purposefully raise "bugs" to test against.
In older versions of this plugin, it was possible to do something like this:
Note: The above more-or-less still works with some built-in plugins (e.g. checkstyle)
In the current version of the plugin my cleanest way to do configure it is something like this:
This will still run spotbugs against the test suite though, and for the dev teams that would rather disable it, it's unnecessary build delays.
Of course I know I can wrap the whole thing in a plugin and fiddle with anything I want. The work done to improve this plugin over previous versions is awesome, especially breaking the reliance/exposure of gradle's ever-changing internal apis. But, I'd rather not add unique behavior just for us.
So tl;dr: I want a simple way to disable spotbugs against tests. One way would be to expose configurations of the source sets. If the latter is ok, I'd be interested in contributing.