I have the following Gradle build file: https://github.com/markuswustenberg/jsense/blob/a796055f984ec309db3cc0f3e8340cbccac36e4e/jsense-protobuf/build.gradle which includes:
checkstyle {
// TODO The excludes are not working, ignore failures for now
//excludes '**/org/jsense/serialize/protobuf/gen/**'
ignoreFailures = true
showViolations = false
}
findbugs {
// TODO The excludes are not working, ignore failures for now
//excludes '**/org/jsense/serialize/protobuf/gen/**'
ignoreFailures = true
}
As you can see, I'm trying to exclude auto-generated code in the package org.jsense.serialize.protobuf.gen. I cannot figure out the format of the strings given to the excludes parameter, and the documentation isn't of much help: http://www.gradle.org/docs/1.10/dsl/org.gradle.api.plugins.quality.FindBugs.html#org.gradle.api.plugins.quality.FindBugs:excludes (it just says "The set of exclude patterns.").
So my question is: How should the excludes pattern strings be formatted for both the Findbugs and Checkstyle plugins?
I'm running Gradle 1.10.
Thanks!
EDIT 1: I got the Checkstyle exclude working with the following:
tasks.withType(Checkstyle) {
exclude '**/org/jsense/serialize/protobuf/gen/**'
}
However, using the exact same exclude on the Findbugs plugin doesn't work:
tasks.withType(FindBugs) {
exclude '**/org/jsense/serialize/protobuf/gen/*'
}
EDIT 2: The accepted answer works, and so does using an XML file and filtering on that, like so:
findbugs {
excludeFilter = file("$projectDir/config/findbugs/excludeFilter.xml")
}
and
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Package name="org.jsense.serialize.protobuf.gen"/>
</Match>
</FindBugsFilter>
EDIT 3: This works great, and no XML file is needed:
def excludePattern = 'org/jsense/serialize/protobuf/gen/'
def excludePatternAntStyle = '**/' + excludePattern + '*'
tasks.withType(FindBugs) {
classes = classes.filter {
!it.path.contains(excludePattern)
}
}
tasks.withType(Checkstyle) {
exclude excludePatternAntStyle
}
tasks.withType(Pmd) {
exclude excludePatternAntStyle
}
SourceTask#exclude
filters source files. However, FindBugs primarily operates on class files, which you'll have to filter as well. Try something like:
tasks.withType(FindBugs) {
exclude '**/org/jsense/serialize/protobuf/gen/*'
classes = classes.filter {
!it.path.contains(new File("org/jsense/serialize/protobuf/gen/").path)
}
}
PS: It could be that filtering source files makes no difference (and therefore isn't necessary) in case of FindBugs. (I haven't tried though.)
If someone looking for a modern day solution:
For checkstyle, you can use something like this in build.gradle:
checkstyleMain.exclude '**/org/jsense/serialize/protobuf/gen/**'
If you want to exclude more than one path
solution 1:
checkstyleMain.exclude '**/org/jsense/serialize/protobuf/gen/**'
checkstyleMain.exclude '**/org/example/some/random/path/**'
solution 2:
checkstyleMain {
setExcludes(new HashSet(['**/org/jsense/serialize/protobuf/gen/**', '**/org/example/some/random/path/**']))
}
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