Domanda

We use Checkstyle to enforce basic code quality rules in our multi-project Gradle build. Some of these rules apply across all file types, not just Java files, but we can't figure out how to configure the Checkstyle Plugin to look at anything other than $projectDir/src/$sourceSet/java.

One of the most basic rules we'd like to enforce is that tab characters never be used. The relevant bits of checkstyle.xml:

<module name="Checker">
  <module name="FileTabCharacter">
    <property name="eachLine" value="true"/>
  </module>
</module>

and the snippet of build.gradle that configures the plugin:

apply plugin: 'checkstyle'
checkstyle {
  configFile = new File(rootDir, 'checkstyle.xml')
}

In addition to java/**/* we'd also like to check all files in conf/**/* and www/**/* (assuming include specs are relative to the source set root). However, if I try adding those include rules:

apply plugin: 'checkstyle'
checkstyle {
  configFile = new File(rootDir, 'checkstyle.xml')
  include 'conf/**/*'
  include 'www/**/*'
}

we get the following error:

> Could not find method include() for arguments [conf/**/*] on org.gradle.api.plugins.quality.CheckstyleExtension_Decorated@467763f.
È stato utile?

Soluzione

You can achieve this by configuring the appropriate Checkstyle task directly. For example:

tasks.checkstyle { // `checkstyle` alone refers to the extension, not the task
    source "src/main/conf"
    source "src/main/www"
}

For more information, see Checkstyle in the Gradle Build Language Reference.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top