Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable checkstyle rules for tests in gradle?

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

like image 590
xenoterracide Avatar asked Sep 25 '15 00:09

xenoterracide


People also ask

How do I disable Gradle test?

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.

How do you exclude test cases in build Gradle?

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.

How do I run checkstyle with Gradle?

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.

Where is the checkstyle configuration path present?

The default location of checkstyle. xml file is <root project directory>/config/checkstyle/checkstyle.


2 Answers

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
}
like image 166
xenoterracide Avatar answered Oct 03 '22 02:10

xenoterracide


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']);
like image 36
barfuin Avatar answered Oct 03 '22 04:10

barfuin