How to use checkstyle in milestone 8

Hi,

I have a simple question: How do I use the checkstyle plugin and exclude some files? I tried

apply plugin: 'checkstyle'
          checkstyle{
        excludes ='**/generated-sources/**/*'
    }

but unfortunately that does not work.

Hi,

the check style plugin creates a check style task for each java source set. To exclude files for quality check, you can use the matching operator of FileTree. Here is a tiny example snippet for excluding files in the checkstyleMain task:

checkstyleMain{
 source = sourceSets.main.allJava.matching{
  exclude '**/generated-sources/**/*'
 }
}

For details of the Checkstyle task you might want to have look at the DSL reference: http://gradle.org/docs/current/dsl/org.gradle.api.plugins.quality.Checkstyle.html or at the Checkstyle chapter of the user guide at: http://gradle.org/docs/current/userguide/checkstyle_plugin.html

regards, René

This also doesn’t work. I have the following config:

sourceSets {
    main { java { srcDirs += "src/generated-sources/java" } }
}
  checkstyleMain {
    source = sourceSets.main.allJava.matching{ exclude '**/generated-sources/**/*' }
}

and in the folder src/generated-sources/java/org/example/test/ java classes. When I write

checkstyleMain {
    source = sourceSets.main.allJava.matching{ exclude '**/org/example/**/*' }
}

it works fine. When I write

sourceSets {
    main { java { srcDirs += "src/generated-sources/java" } }
}
checkstyleMain {
    source = sourceSets.main.allJava.matching{ exclude '**/java/**/*' }
}

it is also not working. When I write

sourceSets {
    main { java { srcDirs += "src/generated-sources/java/org" } }
}
checkstyleMain {
    source = sourceSets.main.allJava.matching{ exclude '**/org/example/**/*' }
}

it’s again not working. So there is a relation to the definition of the source set or am i missing something?

You’re mixing source directories and packages up here. the “exclude” mechanism in the checkstyleMain configuration works on packages only. When you add “src/generated-sources/java” as a root source folder to your main java source set, you cannot define “exclude” on the path of this root folder.

Another way to solve this might be to put your generated sources in a separate source set, which brings some other advantages in my opinion.

regards, René

ah ok. thx for this insight