I have been trying to run spotbugs plugin on my projects using a global build.gradle setup. The plugin is added and seems that build is running. Build and spotbugsMain both are successful when I run them using
./gradlew :com.myproject.something:build --stacktrace
./gradlew :com.myproject.something:spotbugsMain --stracktrace
But if I understand it correctly, it should generate a report (in spotbugs folder?) under build-gradle folder.
I do not see anything generated. spotbugs folder itself is not showing up.
Here is my build.gradle. Can someone please tell me what I am doing wrong? I am not sure I understand concepts of gradle completely but I have tried to use other references.
Minimal working SpotBugs setup for Android Studio
plugins {
id "com.github.spotbugs" version "4.7.2" apply false
}
group = 'com.myproject'
subprojects {
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'com.github.spotbugs'
buildDir = 'build-gradle'
spotbugs {
toolVersion = '4.3.0'
ignoreFailures = false
showStackTraces = true
showProgress = true
effort = 'max'
reportLevel = 'high'
maxHeapSize = '1g'
reportsDir = file("$buildDir/spotbugs")
}
tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
group 'Verification'
description 'Run Spotbugs on this project.'
dependsOn 'assemble'
reports {
xml.enabled = false
html.enabled = true
}
classDirs = files('$buildDir.absolutePath/build-gradle/classes/java/main')
sourceDirs = files('$buildDir.absolutePath/src/main/java')
}
repositories {
// the order here is important. Repositories are queried in the exact order specified here
mavenLocal()
mavenCentral()
maven {
url = uri('http://build.myproject.com:8081/nexus/content/repositories/snapshots')
allowInsecureProtocol = true
}
maven {
url = uri('http://build.myproject.com:8081/nexus/content/repositories/releases')
allowInsecureProtocol = true
}
maven {
url = uri('http://build.myproject.com:8081/nexus/content/repositories/myproject')
allowInsecureProtocol = true
}
maven {
url = uri('http://build.myproject.com:8081/nexus/content/repositories/thirdparty')
allowInsecureProtocol = true
}
}
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
test {
filter {
excludeTestsMatching "*IT"
environment 'RESOURCES_PATH', 'build-gradle/resources/test'
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
}
UPDATE : 07/26/2021
I tried to run full build including all the subprojects instead of individual subproject as mentioned above. I used command
./gradlew clean build --stacktrace
This time, it did not work! The full build is throwing an error as below.
Task :com.vmturbo.mediation.applicationserver.jboss:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':com.myproject.something:compileJava'.
Could not resolve all files for configuration ':com.myproject.something:compileClasspath'.
Could not find com.github.spotbugs:spotbugs-annotations:4.7.2.
Searched in the following locations:
- file:/Users/myuser/.m2/repository/com/github/spotbugs/spotbugs-annotations/4.7.2/spotbugs-annotations-4.7.2.pom
- https://repo.maven.apache.org/maven2/com/github/spotbugs/spotbugs-annotations/4.7.2/spotbugs-annotations-4.7.2.pom
- http://build.myproject.com:8081/nexus/content/repositories/snapshots/com/github/spotbugs/spotbugs-annotations/4.7.2/spotbugs-annotations-4.7.2.pom
- http://build.myproject.com:8081/nexus/content/repositories/releases/com/github/spotbugs/spotbugs-annotations/4.7.2/spotbugs-annotations-4.7.2.pom
- http://build.myproject.com:8081/nexus/content/repositories/myproject/com/github/spotbugs/spotbugs-annotations/4.7.2/spotbugs-annotations-4.7.2.pom
- http://build.myproject.com:8081/nexus/content/repositories/thirdparty/com/github/spotbugs/spotbugs-annotations/4.7.2/spotbugs-annotations-4.7.2.pom
Required by:
project :com.myproject.something
Any idea about the problem? It seems full build does not work with above error and if I try to build only 1 subproject com.myproject.something then it runs fine but does not generate anything related to spotbugs.