简体   繁体   中英

Spotbugs exclude filter in gradle project

I am new to gradle and am trying to configure Spotbugs. I've added the plugin to the build.gradle and the spotbugs issues showed up. However I want to exclude the Findbugs EI_EXPOSE_REP and EI_EXPOSE_REP2 rules, because they show up for all my getter and setters. I have the following snippet in build.gradle:

apply plugin: 'java'
apply plugin: 'com.github.spotbugs'
apply plugin: 'findbugs'

spotbugs {
    toolVersion = '5.0.0'
}

tasks.withType(SpotBugsTask) {
    reports {
        xml.enabled = false
        html.enabled = true
    }
}

findbugs {
    excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml")
    toolVersion = "3.0.1"
    effort = "max"
}

The excludeFilter.xml contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
    <Match>
        <Bug pattern="EI_EXPOSE_REP"/>
    </Match>
    <Match>
        <Bug pattern="EI_EXPOSE_REP2"/>
    </Match>
</FindBugsFilter>

I also tried adding the exclude like this:

tasks.withType(FindBugs) {
    excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml")
}

But it didn't work out, so probably I am missing something.

Try to add the exclude filter to the spotbugs configuration instead of findbugs: so you should probably try:

spotbugs {
    toolVersion = '5.0.0'
    excludeFilter.set(file("${spotbugsConfigDir}/excludeFilter.xml"))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM