How to not run checkstyle/findbugs tasks automatically


(Dan Ciarniello) #1

Hi,

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.


(René Groeschke) #2

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.

cheers!


(Dan Ciarniello) #3

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.


How do I conditionally disable findbugs / checkstyle / pmd / codenarc?
(Luke Daley) #4

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


(Dan Ciarniello) #5

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.

gradle.properties: findbugs = false

build.gradle: apply plugin: ‘findbugs’ … findbugsMain.onlyIf {project.properties[‘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.


(Peter Niederwieser) #6

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’.


(Dan Ciarniello) #7

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

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

This does exactly what I was looking for.

Thanks!


(Peter Niederwieser) #8

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.


(Dan Ciarniello) #9

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?


(Peter Niederwieser) #10

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


(Dan Ciarniello) #11

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

Thanks again, Dan.