with maven I disabled checkstyle for tests, how can I disable the checkstyleTest
task in gradle?
I've tried variations o these separately
checkstyle {
toolVersion = '6.10.1'
exclude '**/*Test.java'
}
checkstyleTest {
sourceSets = []
}
it all ends up in errors
To skip unit tests from gradle build you can use the -x or --exclude-task option. By using -x option you can skip or ignore any gradle task as well.
To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build.
To use checkstyle in Gradle you have add the plug-in to your build. gradle and provide a config\checkstyle\checkstyle. xml checkstyle configuration file. A detailed example is given in the checkstyle with Gradle exercise.
The default location of checkstyle. xml file is <root project directory>/config/checkstyle/checkstyle.
Apparently you can set the undocumented (maybe underdocumented? maybe it's inherited or something ) enabled
property on checkstyleTest
(and to access that in the closure is in no way obvious by the documentation) to false
.
checkstyle {
toolVersion = '6.10.1'
checkstyleTest.enabled = false
}
The cleanest way is to tell Gradle to execute only the Checkstyle tasks that you need, by specifying them like so:
checkstyle {
toolVersion = '6.10.1'
sourceSets = [project.sourceSets.main]
}
Just disabling the unneeded tasks would also work, but I think the above is cleaner.
In the above example, the checkstyleTest
task will remain in the task list, even though it is not executed. I prefer a clean task list, so you can remove the unused task via
project.tasks.remove(project.tasks['checkstyleTest']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With