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') | |
} | |
} | |
} | |
} |
Hi !
I don't succeed to configure spotBugs for an Android project.
When using your gist, I have the following error :A problem occurred evaluating project ':app'.
org.gradle.api.plugins.quality.internal.AbstractCodeQualityPlugin.configureConfiguration(Lorg/gradle/api/artifacts/Configuration;)V
When upgrading spotbugs to the official version (ie 1.7.1), Studio indicates me to use Gradle 5.0 or later.
Do you have any example, please ?
Well, as you'are using Gradle v4 - lastest Spotbugs version you could use only 1.6.6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi !
I don't succeed to configure spotBugs for an Android project.
When using your gist, I have the following error :
When upgrading spotbugs to the official version (ie 1.7.1), Studio indicates me to use Gradle 5.0 or later.
Do you have any example, please ?