Connecting Checkstyle to integration tests

We have the following way of setting up an “integrationTests” task:

task integrationTests(type: Test) {

include ‘**/*IntegrationTest.class’


We also use the checkstyle plugin, which creates tasks “checkstyleMain” and “checkstyleTest” which the the task “check” depends on.

We have now realized that it works better for us to run checkstyle in connection with running integration tests, and NOT run checkstyle in every build. Making “integrationTests” depend on checkstyleMain is easy of course, but how do we remove the “check” task’s dependency on “checkstyleMain”?

Instead of making ‘integrationTests’ depend on ‘checkstyleMain’ (which isn’t quite correct because the former task doesn’t require the latter to be run), I’d do something like ‘task integrationChecks { dependsOn integrationTests, tasks.withType(CheckStyle) }’. To prevent CheckStyle from being run as part of ‘check’/‘build’, you can do ‘checkstyle { sourceSets = [] }’.