Replies: 2 comments 4 replies
-
Here is what i've managed to fabricate, but i'm new to gradle and i'm sure it can be done in a better way. PS: The spotbugs invocation can be further "incremented" by using Incremental inputs, but i think it would require some changes in the code of the plugin. def spotbugsReportFile = file("${buildDir}/spotbugs/spotbugs.html")
tasks.named("spotbugsMain"){
enabled = false
reports {
html {
required = true
outputLocation = spotbugsReportFile
}
}
}
tasks.register("spotbugsCaching"){
description "declares inputs and outputs so the gradle incremental rules apply"
//https://docs.gradle.org/current/userguide/incremental_build.html#incremental_build
dependsOn "compileJava"
outputs.file(spotbugsReportFile)
finalizedBy "spotbugsMain"
doLast{
tasks.spotbugsMain.enabled(true)
}
}
tasks.register("spotbugsChecking"){
description "check spotbugs results, when the cached task is skipped because of incremental builds"
doLast{
if(!tasks.spotbugsCaching.didWork) {
//TODO: somehow store and use findBugs2.getErrorCount() or errorCountingBugReporter.getErrorCount(), instead of relying on the report and some text inside.
String marker = "warningtable";
if (spotbugsReportFile.exists()) {
if (spotbugsReportFile.getText("UTF-8").indexOf(marker) != -1) {
throw new GradleException("Spotbugs errors! See the report at: ${spotbugsReportFile}")
}
}
}
}
}
tasks.named("classes"){
dependsOn("spotbugsCaching")
dependsOn("spotbugsChecking")
}
|
Beta Was this translation helpful? Give feedback.
-
But in vanilla configuration spotbugs is skipped only if there were no errors in the previous build. I've cleared the first version to this one. I'm still quite new to gradle and there probably are still lots wrong things, so i'm grateful for any improvements. def spotbugsReportFile = file("${buildDir}/spotbugs/spotbugs.html")
tasks.named("spotbugsMain"){
//will be enabled by spotbugs if need to be run
enabled = false
reports {
html {
required = true
outputLocation = spotbugsReportFile
}
}
}
tasks.named("compileJava"){
doLast{
//clean the spotbugs report file, so the spotbugs is not cached
delete(spotbugsReportFile);
}
}
tasks.register("spotbugs"){
description = "Use this task to invoke spotbugs checks"
group = JavaBasePlugin.VERIFICATION_GROUP
dependsOn "compileJava"
//initially is disabled - will be enabled if needed
finalizedBy "spotbugsMain"
doLast{
//if spotbugs was cached - check the results file, and fail if there is error
if (spotbugsReportFile.exists()) {
String marker = "warningtable";
if (spotbugsReportFile.getText("UTF-8").indexOf(marker) != -1) {
throw new GradleException("Spotbugs errors! See the report at: ${spotbugsReportFile}")
}
}
else{
//the spotbugs error status is unknown so enable execution of spotbugsMain to recalculate it
tasks.spotbugsMain.enabled(true)
}
}
}
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I have a big multi-module project and spotbugs is the slowest part of the build.
Is it possible to configure the spotbugs tasks so they are used incrementally only on changed sources and even skip the task execution if there is no changes in the sources?
At the moment the spotbugs tasks are executed on every module every time no matter if there are changes or not.
I'm using the Gradle 8.0.2 and 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.12'
Beta Was this translation helpful? Give feedback.
All reactions