Last active
October 6, 2019 05:53
-
-
Save mik9/fdde79052fef7f03c4325734701a39d7 to your computer and use it in GitHub Desktop.
Findbugs/Spotbugs task configuration for Android project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isCi = System.getenv().JOB_NAME != null | |
buildscript { | |
repositories { | |
maven { url "https://plugins.gradle.org/m2/" } | |
} | |
dependencies { | |
classpath "gradle.plugin.com.github.spotbugs:gradlePlugin:1.6.0" | |
} | |
} | |
// ... | |
apply plugin: "com.github.spotbugs" | |
// ... | |
spotbugs { | |
toolVersion spotbugsVersion | |
excludeFilter = file('cq-configs/findbugs/findbugs_bug_filter.xml') | |
// Search better | |
effort = 'max' | |
// Report all | |
reportLevel = 'low' | |
} | |
def spotbugsTask = task('spotbugs') { | |
description 'Run spotbugs' | |
group 'Verification' | |
} | |
def spotbugsReports | |
if (isCi) { | |
// Run Spotbugs twice on CI to generate both reports | |
spotbugsReports = [ 'Html', 'Xml' ] | |
} else { | |
// But run only once on local machine | |
spotbugsReports = [ 'Html' ] | |
} | |
android.applicationVariants.all { variant -> | |
spotbugsReports.each { reportType -> | |
task("spotbugs${reportType}${variant.name.capitalize()}", type: SpotBugsTask, dependsOn: variant.javaCompiler) { | |
description "Run spotbugs for ${variant.name}" | |
group 'Verification' | |
classes = variant.javaCompiler.getOutputs().getFiles().getAsFileTree() + fileTree("build/tmp/kotlin-classes/${variant.name}/") | |
source = variant.javaCompiler.source | |
classpath = variant.javaCompiler.classpath.asFileTree | |
reports { | |
html.enabled = reportType == 'Html' | |
xml.enabled = reportType == 'Xml' | |
html.stylesheet resources.text.fromFile('cq-configs/findbugs/findbugs-html.xsl') | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, as you'are using Gradle v4 - lastest Spotbugs version you could use only 1.6.6