How to not run checkstyle/findbugs tasks automatically


I’ve added the checkstyle and findbugs plugins to a project. The problem for me is that their respective tasks are invoked automatically as part of the build process. Because they slow the build process down (especially findbugs), I would prefer to run them on demand.

How can this behaviour be configured?

Thanks, Dan.

it depends on what tasks are passed via commandline. if you call “gradle build”, this will trigger the check task that depends on the according findbugs/ checkstyle tasks. the straight forward way would be to trigger a different tasks (eg “assemble test”). you can also exclude tasks using the “-x” flag on the commandline.


Hi, Rene.

I know that I could use the “-x” flag but doign “gradle build -x findbugsMain -x findbugsTest -x checkStyleMain -x checkStyleTest” every time is a bit unwieldy. What I would like to be able to do is to run “gradle build” and not have any of the findbugs or checkstyle tasks run. I would explicitly run the tasks (e. g. “gradle findbugsMain”) whenever I would want to analyze the code.

In effect, I’m looking for a way to remove the dependency on findbugs and checkstyle from the build task (or whichever task is relevant).

Thanks, Dan.

Removing dependencies is problematic. What you can try is programmatically adding excludes via ‘gradle.startParameter.excludedTaskNames’ in your build script.

Unfortunately, that doesn’t work. Any task added to excludedTaskNames will not be executed even if it’s explicitly specified on the command line.

It looks like the only solution is to do use properties.

E. g. findbugs = false

build.gradle: apply plugin: ‘findbugs’ … findbugsMain.onlyIf {[‘findbugs’].toBoolean()}

This will cause findbugsMain to be skipped unless the property is overridden:

gradle -Pfindbugs=‘true’ findbugsMain

It works but it’s a bit unwieldy to have to specify the property to do this.

Actually, there is a feature for what you want:

findbugs {
    sourceSets = []
  checkstyle {
    sourceSets = []

Now, none of the tasks will run as part of ‘check’/‘build’.

Actually, I like your other (emailed directly) solution better:

tasks.withType(FindBugs) { task -> enabled = gradle.startParameter.taskNames.contains( }

This does exactly what I was looking for.


The problem with this solution is that any task dependencies of the code quality tasks will still run. Conversely, ‘sourceSets = []’ will prevent the build/check tasks from depending on the code quality tasks, which is exactly what you asked for. (The tasks will still be available for manual execution.)

PS: I didn’t email the first proposal directly, I just edited the post once I found what I considered a better solution.

Ah, didn’t notice that you had edited the original.

In any case, wouldn’t setting the sourceSets to empty prevent the tasks from running even when explicitly specified on the command line?

No it won’t. This is about which source sets should be checked by default (i.e. when executing the ‘build’ or ‘check’ task).

Ok. I understand and now that I’ve actually tried it, yes it works.

Thanks again, Dan.