Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use Spotbugs in Android application #90

Open
ZOlbrys opened this issue Dec 24, 2018 · 41 comments · May be fixed by #281
Open

Unable to use Spotbugs in Android application #90

ZOlbrys opened this issue Dec 24, 2018 · 41 comments · May be fixed by #281

Comments

@ZOlbrys
Copy link

ZOlbrys commented Dec 24, 2018

Hey all,

I've recently tried to get Spotbugs working in a sample Android application and I haven't had any luck.

Here's a sample project showing my attempt: https://github.com/ZOlbrys/SpotbugsExample

When I try to run Spotbugs via gradle, I see this error:

Zachs-MBP:SpotbugsExample Zach$ ./gradlew spotbugs --stacktrace

FAILURE: Build failed with an exception.

* What went wrong:
Error while evaluating property 'allSource' of task ':app:spotbugs'
> path may not be null or empty string. path='null'

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.InvalidUserDataException: Error while evaluating property 'allSource' of task ':app:spotbugs'
        at org.gradle.api.internal.tasks.properties.GetInputPropertiesVisitor$1.create(GetInputPropertiesVisitor.java:58)
        at org.gradle.api.internal.tasks.properties.GetInputPropertiesVisitor$1.create(GetInputPropertiesVisitor.java:48)
        at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.snapshotTaskInputProperties(CacheBackedTaskHistoryRepository.java:303)
        at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.createExecution(CacheBackedTaskHistoryRepository.java:146)
        at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.access$100(CacheBackedTaskHistoryRepository.java:61)
        at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository$1.getCurrentExecution(CacheBackedTaskHistoryRepository.java:111)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:208)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:93)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:50)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.IllegalArgumentException: path may not be null or empty string. path='null'
        at org.gradle.api.internal.file.AbstractBaseDirFileResolver.doResolve(AbstractBaseDirFileResolver.java:65)
        at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:85)
        at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:67)
        at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext$FileCollectionConverter.convertInto(DefaultFileCollectionResolveContext.java:188)
        at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(DefaultFileCollectionResolveContext.java:143)
        at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileCollections(DefaultFileCollectionResolveContext.java:95)
        at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext$FileCollectionConverter.convertInto(DefaultFileCollectionResolveContext.java:172)
        at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(DefaultFileCollectionResolveContext.java:112)
        at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileCollections(DefaultFileCollectionResolveContext.java:95)
        at org.gradle.api.internal.file.CompositeFileCollection.getSourceCollections(CompositeFileCollection.java:172)
        at org.gradle.api.internal.file.CompositeFileCollection.getFiles(CompositeFileCollection.java:55)
        at org.gradle.api.internal.tasks.properties.GetInputPropertiesVisitor.prepareValue(GetInputPropertiesVisitor.java:74)
        at org.gradle.api.internal.tasks.properties.GetInputPropertiesVisitor.access$100(GetInputPropertiesVisitor.java:34)
        at org.gradle.api.internal.tasks.properties.GetInputPropertiesVisitor$1.create(GetInputPropertiesVisitor.java:55)
        ... 35 more


* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed

Here's my build.gradle app file:

apply plugin: 'com.android.application'
apply plugin: 'com.github.spotbugs'

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' }
    }

    dependencies {
        classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.8'
    }
}

spotbugs {
    toolVersion = '3.1.10'
}

task spotbugs (type: com.github.spotbugs.SpotBugsTask) {
    ignoreFailures = true
    effort = 'max'
    reportLevel = 'high'

    classes = files("${project.buildDir}/intermediates/javac")
    source = 'src'
    classpath = files()

    reports {
        xml.enabled = false
        html.enabled = true
        html.destination = file("$project.buildDir/outputs/spotbugs/spotbugs.html")
    }
}

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.zach.spotbugsexample"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

I am running into these bugs on Android Studio 3.2.1 and Android Studio 3.3 RC2. Am I doing something wrong here? Thanks!

@welcome
Copy link

welcome bot commented Dec 24, 2018

Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

@KengoTODA KengoTODA transferred this issue from spotbugs/spotbugs Dec 24, 2018
@KengoTODA
Copy link
Member

@ZOlbrys please define sourceSet that is not generated by Android gradle plugin. Here we have document that describes how-to.

@ZOlbrys
Copy link
Author

ZOlbrys commented Dec 24, 2018

@KengoTODA Thanks for the response. I've added this, and now encounter a new error:

Zachs-MBP:SpotbugsExample Zach$ ./gradlew spotbugsMain

> Task :app:compileJava FAILED
/Users/zach/Developer/Code/SpotbugsExample/app/src/main/java/com/example/zach/spotbugsexample/MainActivity.java:3: error: package android.support.v7.app does not exist
import android.support.v7.app.AppCompatActivity;
                             ^
/Users/zach/Developer/Code/SpotbugsExample/app/src/main/java/com/example/zach/spotbugsexample/MainActivity.java:4: error: package android.os does not exist
import android.os.Bundle;
                 ^
/Users/zach/Developer/Code/SpotbugsExample/app/src/main/java/com/example/zach/spotbugsexample/MainActivity.java:6: error: cannot find symbol
public class MainActivity extends AppCompatActivity {
                                  ^
  symbol: class AppCompatActivity
/Users/zach/Developer/Code/SpotbugsExample/app/src/main/java/com/example/zach/spotbugsexample/MainActivity.java:9: error: cannot find symbol
    protected void onCreate(Bundle savedInstanceState) {
                            ^
  symbol:   class Bundle
  location: class MainActivity
/Users/zach/Developer/Code/SpotbugsExample/app/src/main/java/com/example/zach/spotbugsexample/MainActivity.java:8: error: method does not override or implement a method from a supertype
    @Override
    ^
/Users/zach/Developer/Code/SpotbugsExample/app/src/main/java/com/example/zach/spotbugsexample/MainActivity.java:10: error: cannot find symbol
        super.onCreate(savedInstanceState);
        ^
  symbol:   variable super
  location: class MainActivity
/Users/zach/Developer/Code/SpotbugsExample/app/src/main/java/com/example/zach/spotbugsexample/MainActivity.java:11: error: package R does not exist
        setContentView(R.layout.activity_main);
                        ^
7 errors


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s

It looks like it's unable to find the sources/code for most of the android related classes.

@KengoTODA
Copy link
Member

Thanks for your report, I also reproduced this problem in my local.

Then maybe we are facing something unknown, I'll wait contribution from gradle/android experts...

@AEFeinstein
Copy link

I experienced the same issue today. I'm not sure if it's a problem with spotbugs or something else, because the actual task that is failing for both @ZOlbrys and me is Execution failed for task ':app:compileJava'.

@AEFeinstein
Copy link

AEFeinstein commented Jan 2, 2019

Upon further inspection, the :mobile:compileJava task didn't exist before adding spotbugs. Diffing the output of gradlew.bat tasks --all before and after adding spotbugs, these tasks are new:

mobile:spotbugsMain - Run SpotBugs analysis for main classes
mobile:checkstyleMain - Run Checkstyle analysis for main classes
mobile:pmdMain - Run PMD analysis for main classes
mobile:classes - Assembles main classes.
mobile:compileJava - Compiles main Java source.
mobile:processResources - Processes main resources.

Those tasks all fail because mobile:compileJava fails. Android gradle seems to have the following tasks to compile Java, maybe spotbugs should be dependent on one of them instead of :mobile:compileJava:

mobile:compileDebugAndroidTestJavaWithJavac
mobile:compileDebugJavaWithJavac
mobile:compileDebugUnitTestJavaWithJavac
mobile:compileReleaseJavaWithJavac
mobile:compileReleaseUnitTestJavaWithJavac

@AEFeinstein
Copy link

Adding the following task to my gradle file allowed spotbugs to run correctly:

task compileJava(overwrite: true) {
    dependsOn 'compileDebugJavaWithJavac'
    group = "build"
}

@ZOlbrys
Copy link
Author

ZOlbrys commented Jan 5, 2019

@AEFeinstein interesting - I'm still not getting this to work! I added that to my test project, but now I get this error:

Zachs-MBP:SpotbugsExample Zach$ ./gradlew spotbugsMain

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:spotbugsMain'.
> com.github.spotbugs.internal.SpotBugsReportsInternal.getEnabledReports()Ljava/util/Map;

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
16 actionable tasks: 1 executed, 15 up-to-date
Zachs-MBP:SpotbugsExample Zach$ 

Is my gradle file setup incorrectly? I wasn't able to find exact documentation on this stuff.

@AEFeinstein
Copy link

@ZOlbrys I can't debug your particular problem, but here's my project with the plugin working
https://github.com/AEFeinstein/mtg-familiar
You can compare our gradle files and hopefully figure it out.

@ZOlbrys
Copy link
Author

ZOlbrys commented Jan 14, 2019

@AEFeinstein Thanks for reaching out! I saw the files your gradle files and setup mine in a similar manner. I still see the same error though - so no progress, maybe. @KengoTODA any thoughts on the issue above? #90 (comment)

@KengoTODA
Copy link
Member

No idea, I'm not Android guy...

@AEFeinstein
Copy link

@ZOlbrys what happens when you run gradlew.bat compileDebugJavaWithJavac and gradlew.bat compileJava?

@ZOlbrys
Copy link
Author

ZOlbrys commented Jan 15, 2019

@KengoTODA understood - thanks for the support so far though! Appreciate it :)

@AEFeinstein good news! I upgraded to Android Studio 3.3, and then ran the commands and that seems to have fixed my problem. I think the Android Studio update helped more than anything else - I see you were using a newer version of gradle as well... Anyways, I am able to run the tool now and verified that bugs are being reported.

Thanks for the assistance!

@fredgrott
Copy link

note @AEFeinstein has it wrong..

missing stuff wrap it the same way you flavors with buildtypes and one needs to add

variant.javaCompiler files to classpath for other project modules
also need classpath as it will no even run without that

my first run I just did it with the buildType of variant and got it to run correctly
now polishing it so it does product flavors correctly along with proper task renaming to spotbugsBuildTypeVariant task

also note do a first run so that you know what to set the filter file to as you want to exclude the all the android lib stuff and your 3rd party libs

However, I can confirm its working which is nice cause I still have problems attempting to use errorprone with kotlin right now..so its life saver

if anyone wants to take a look, the project I am putting it into with the
polished modifications of task setup is at my gitlab project of

https://gitlab.com/fred.grott/droikotlinkit

also note my solution points to the kotlin java classes correctly

so I hope it helps those who are still stuck with it not working..

just call me Android Gradle-Plugin expert :)

@MatFl
Copy link

MatFl commented Jan 22, 2019

I would like to use spotbugs in our Android application, but creating a sourceSet and a javaCompile task for this seems so wrong.

If the SpotBugsTask would have a setter for the sourceDirs field, without using SourceSets we could get the required input from the AndroidSourceSets. Unfortunately the AndroidSourceSet does not implement the plain gradle SourceSet, so this does not work.

We can directly call setSource on the Task, but then spotbugs complains here:

return getProject().files(sourceDirs).plus(getSource());

that sourceDirs is not set. I actually don't understand the use for the sourceDir variable, because the setSourceSet also calls setSource. So in getAllSource the sources are added twice?

So if the SpotbugsTask either

  • provides a setSource method with a Set<File> parameter

or

  • gets rid of the sourceDirs variable in getAllSource

we could easily get Spotbugs to work with Android.

@davidburstromspotify
Copy link
Contributor

@MatFl I also came to the same conclusion: If there is no sourceSet set, the sourceDirs Set will be uninitialized. From my point of view, initializing it in the constructor with new HashSet() or Collections.emptySet() should do the trick.

@fredgrott
Copy link

okay let me add a brief code ex

its a multi module project with no app flavors

project.extensions.extraProperties.set('SpotBugsTask', com.github.spotbugs.SpotBugsTask)

spotbugs {
    toolVersion = '3.1.10'
    ignoreFailures = false

    excludeFilter = file("${rootDir}/config/findbugs-exclude-filter.xml")

    // Search better
    effort = 'max'
    // Report all
    reportLevel = 'low'
}

sourceSets {
    // we define `main` sourceSet here, so SpotBugs Gradle Plugin generates `spotbugsMain` task
    main {
        java.srcDirs = ['src/main/java']
    }
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
    dependsOn 'assembleDebug'
    group = "verification"

    classes = fileTree("build/inteermediates/javac/debug/") + fileTree("build/tmp/kotlin-classes/debug/")
    ignoreFailures = true
    classpath = files()
    // configure automatically generated tasks
    reports {
        xml.enabled = false
        html.enabled = true
        html {
            destination file("$project.buildDir/outputs/reports/spotbugs/spotbugs-debug.html")
            stylesheet resources.text.fromFile("$rootDir/config/fancy.xsl")
        }
    }
}
task compileJava(overwrite: true) {
    dependsOn 'compileDebugJavaWithJavac'
    group = "build"
}

so that is the general setup and works fine, note you will get a xerces xml parse warning on the referenced android framework classes but that can be ignored as far as I know

@MatFl
Copy link

MatFl commented Feb 5, 2019

Defining a java sourceSet and compiling the java task is (in my opinion) nothing more than a dirty workaround.
Android already defines sourceSets and build tasks, which however aren't compatible with the java ones. It would be trivial to use them if the SpotbugsTask would provide one of the solutions I mentioned above...

@WonderCsabo
Copy link

I agree with @MatFl . Before changing how getAllSource() behaves, SpotBugs worked well in our multi module Android project. It broke after updating the Spotbugs Gradle Plugin.

@KengoTODA
Copy link
Member

@WonderCsabo which version was working with your project? In my understanding, this plugin already behaved so when our organization forked.

@WonderCsabo
Copy link

Plugin Version 1.6.6 . It broke when changes added for getAllSource(), as explained above.

@KengoTODA
Copy link
Member

Nice share! It'll help our investigation.

@mik9
Copy link

mik9 commented Feb 19, 2019

Hi. I want to share my configuration of spotbugs for android project: https://gist.github.com/mik9/fdde79052fef7f03c4325734701a39d7

Latest working plugin version: 1.6.6. Maybe it helps.

@tobiasKaminsky
Copy link

Starting with 1.6.9 I do get

Error while evaluating property 'allSource' of task ':spotbugsGplayDebug'
> path may not be null or empty string. path='null'

which was fine on 1.6.6.

Config:

android.applicationVariants.all { variant ->
        String variantName = variant.name
        String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1);
        tasks.register("spotbugs${capVariantName}", SpotBugsTask) {
            ignoreFailures = false
            effort = "max"
            reportLevel = "medium"
            classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/compile${capVariantName}JavaWithJavac/classes/")
            excludeFilter = file("${project.rootDir}/findbugs-filter.xml")
            pluginClasspath = project.configurations.spotbugsPlugins
            source = fileTree('src/main/java')
            classpath = files()
            include '**/*.java'
            exclude '**/gen/**'

            reports {
                xml.enabled = false
                html.enabled = true
                html {
                    destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
                }
            }
        }
    }

@tim4dev
Copy link

tim4dev commented Apr 29, 2019

Android Studio 3.4
gradle-5.1.1
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.6'
toolVersion = "3.1.12"
used product flavours.

All versions that are newer than 1.6.6 do not work.

@KengoTODA KengoTODA modified the milestones: 2.0.0, 3.0.0 May 13, 2019
@dublinx333
Copy link

Sorry, no help only observations: Why is this so difficult? Why is there no graceful AND meaningful (by that I mean output any semi-layman could read and understand) output. I call this trouble shooting at the DNA level/cellular level instead of the component level. I was truly saddened when I read "good news! I upgraded to Android Studio 3.3, and then ran the commands and that seems to have fixed my problem.". Imo, sadly nothing has fundamentally change in this 'area' in 35+ years. And this is even sadder. :(

@KengoTODA
Copy link
Member

Hello all, check #180 and help us to confirm that new plugin works with Android project. We'll release stable version right after SpotBugs 4.0.0 release.

@henrychoi7
Copy link

Hi, I tried to use the SpotBugs Gradle Plugin v4.0.2 (which is SpotBugs 4.0.0) in a single Android project and got some errors like below:

* What went wrong:
Execution failed for task ':SpotBugsReports'.
> A failure occurred while executing com.github.spotbugs.snom.internal.SpotBugsRunnerForWorker$SpotBugsExecutor
   > Failed to run Gradle Worker Daemon
      > Process 'Gradle Worker Daemon 4' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

My build.gradle file is like below:

buildscript {
    ext.kotlin_version = "1.3.30"
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.6.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.gms:google-services:4.3.3"
        classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.0.2"
    }
}

apply plugin: "com.github.spotbugs"

tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
    classes = files("$project.buildDir/intermediates/javac")
//    source = fileTree('src/main/java')
    reports {
        // Enable HTML report only
        html.enabled = true
        xml.enabled = false
    }
}

task SpotBugsReports(type: com.github.spotbugs.snom.SpotBugsTask) {
    classes = files("$project.buildDir/intermediates/javac")
//    source = fileTree("src/main/java")
    reports {
        html.enabled = true
        xml.enabled = false
    }
}

The reason I commented the source property is that if I uncomment them, another error pops up like below:

> Could not set unknown property 'source' for task ':SpotBugsReports' of type com.github.spotbugs.snom.SpotBugsTask.

I don't know why but I can't set the source property. Is there anyone with this issue here?

@KengoTODA
Copy link
Member

KengoTODA commented Mar 13, 2020

@henrychoi7 Not only 4.0.2 but also 3.0.0 has no source property, in my understanding...

https://github.com/spotbugs/spotbugs-gradle-plugin/blob/3.0.0/src/main/java/com/github/spotbugs/SpotBugsTask.java

Let me confirm what is your expectation. Do you want to set the source directory to analyse?
Then sourceDirs should be the one.

https://spotbugs-gradle-plugin.netlify.com/com/github/spotbugs/snom/spotbugstask.html#sourceDirs

@henrychoi7
Copy link

henrychoi7 commented Mar 16, 2020

@KengoTODA Thank you!
I'll keep in mind with the reference. I was trying to set the source directory. But then again, if I type the command ./gradlew SpotBugsReports, I get the following error like below:

* What went wrong:
A problem occurred evaluating project ':app'.
> com/android/build/gradle/tasks/AndroidJavaCompile

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:227)
        at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:232)
        at org.gradle.configuration.BuildOperationScriptPlugin$1$1.run(BuildOperationScriptPlugin.java:69)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.configuration.BuildOperationScriptPlugin$1.execute(BuildOperationScriptPlugin.java:66)
        at org.gradle.configuration.BuildOperationScriptPlugin$1.execute(BuildOperationScriptPlugin.java:63)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:49)
        at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:63)
        at org.gradle.configuration.project.BuildScriptProcessor$1.run(BuildScriptProcessor.java:45)
        at org.gradle.internal.Factories$1.create(Factories.java:26)
        at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:201)
        at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:187)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:42)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
        at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:35)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject$1.run(LifecycleProjectEvaluator.java:107)
        at org.gradle.internal.Factories$1.create(Factories.java:26)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:189)
        at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
        at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withProjectLock(DefaultProjectStateRegistry.java:227)
        at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:221)
        at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:187)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject.run(LifecycleProjectEvaluator.java:96)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:68)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:693)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:141)
        at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:36)
        at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:64)
        at org.gradle.configuration.DefaultProjectsPreparer.prepareProjects(DefaultProjectsPreparer.java:55)
        at org.gradle.configuration.BuildOperatingFiringProjectsPreparer$ConfigureBuild.run(BuildOperatingFiringProjectsPreparer.java:52)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.configuration.BuildOperatingFiringProjectsPreparer.prepareProjects(BuildOperatingFiringProjectsPreparer.java:40)
        at org.gradle.initialization.DefaultGradleLauncher.prepareProjects(DefaultGradleLauncher.java:198)
        at org.gradle.initialization.DefaultGradleLauncher.doClassicBuildStages(DefaultGradleLauncher.java:138)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:126)
        at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:106)
        at org.gradle.internal.invocation.GradleBuildController$1.execute(GradleBuildController.java:60)
        at org.gradle.internal.invocation.GradleBuildController$1.execute(GradleBuildController.java:57)
        at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:85)
        at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:78)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:189)
        at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
        at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:78)
        at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:57)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:31)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:63)
        at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
        at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:39)
        at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:51)
        at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:45)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
        at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:45)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:50)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:47)
        at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:78)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:31)
        at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:42)
        at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:28)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:78)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:52)
        at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:59)
        at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:36)
        at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:68)
        at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:38)
        at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:37)
        at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:26)
        at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
        at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
        at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:60)
        at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:32)
        at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:55)
        at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:41)
        at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:48)
        at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:32)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:68)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:27)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: java.lang.NoClassDefFoundError: com/android/build/gradle/tasks/AndroidJavaCompile
        at com.github.spotbugs.snom.internal.SpotBugsTaskFactory.lambda$generateForAndroid$5(SpotBugsTaskFactory.java:72)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction$1$1.run(DefaultCollectionCallbackActionDecorator.java:100)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.reapply(DefaultUserCodeApplicationContext.java:60)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction$1.run(DefaultCollectionCallbackActionDecorator.java:97)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction.execute(DefaultCollectionCallbackActionDecorator.java:94)
        at org.gradle.api.internal.collections.CollectionFilter$1.execute(CollectionFilter.java:59)
        at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:163)
        at org.gradle.api.internal.plugins.DefaultPluginContainer$2.execute(DefaultPluginContainer.java:177)
        at org.gradle.api.internal.plugins.DefaultPluginContainer$2.execute(DefaultPluginContainer.java:169)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction$1$1.run(DefaultCollectionCallbackActionDecorator.java:100)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.reapply(DefaultUserCodeApplicationContext.java:60)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction$1.run(DefaultCollectionCallbackActionDecorator.java:97)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction.execute(DefaultCollectionCallbackActionDecorator.java:94)
        at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:163)
        at org.gradle.api.internal.plugins.DefaultPluginContainer.withId(DefaultPluginContainer.java:181)
        at com.github.spotbugs.snom.internal.SpotBugsTaskFactory.generateForAndroid(SpotBugsTaskFactory.java:68)
        at com.github.spotbugs.snom.internal.SpotBugsTaskFactory.generate(SpotBugsTaskFactory.java:31)
        at com.github.spotbugs.snom.SpotBugsPlugin.createTasks(SpotBugsPlugin.java:49)
        at com.github.spotbugs.snom.SpotBugsPlugin.apply(SpotBugsPlugin.java:45)
        at com.github.spotbugs.snom.SpotBugsPlugin.apply(SpotBugsPlugin.java:23)
        at org.gradle.api.internal.plugins.ImperativeOnlyPluginTarget.applyImperative(ImperativeOnlyPluginTarget.java:43)
        at org.gradle.api.internal.plugins.RuleBasedPluginTarget.applyImperative(RuleBasedPluginTarget.java:51)
        at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:181)
        at org.gradle.api.internal.plugins.DefaultPluginManager.access$300(DefaultPluginManager.java:51)
        at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:276)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:159)
        at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:156)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:49)
        at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:156)
        at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:136)
        at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyType(DefaultObjectConfigurationAction.java:129)
        at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:38)
        at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:93)
        at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:152)
        at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:49)
        at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.java:41)
        at org.gradle.api.Script$apply.callCurrent(Unknown Source)
        at build_1dpe2085z9d703ego26q3jczw.run(/Users/xx/xx/app/build.gradle:129)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
        ... 129 more

Therefore, I can't set apply plugin: "com.github.spotbugs" in the build.gradle (app). Any ideas to this type of issue? If I set apply plugin: "com.github.spotbugs" in the build.gradle (project), it doesn't show the error (but it throws another error). Another error looks like below:

* What went wrong:
Execution failed for task ':app:SpotBugsReports'.
> No value has been specified for this provider.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:SpotBugsReports'.
        at org.gradle.execution.plan.DefaultExecutionPlan.resolveMutations(DefaultExecutionPlan.java:658)
        at org.gradle.execution.plan.DefaultExecutionPlan.getResolvedMutationInfo(DefaultExecutionPlan.java:594)
        at org.gradle.execution.plan.DefaultExecutionPlan.selectNext(DefaultExecutionPlan.java:549)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$2.transform(DefaultPlanExecutor.java:176)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$2.transform(DefaultPlanExecutor.java:163)
        at org.gradle.internal.resources.DefaultResourceLockCoordinationService.withStateLock(DefaultResourceLockCoordinationService.java:45)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:163)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: java.lang.IllegalStateException: No value has been specified for this provider.
        at org.gradle.api.internal.provider.Providers$1.get(Providers.java:32)
        at org.gradle.api.internal.provider.DefaultProperty.get(DefaultProperty.java:157)
        at org.gradle.api.internal.provider.AbstractMappingProvider.get(AbstractMappingProvider.java:45)
        at org.gradle.api.internal.provider.AbstractMappingProvider.get(AbstractMappingProvider.java:45)
        at org.gradle.api.internal.provider.AbstractMappingProvider.get(AbstractMappingProvider.java:45)
        at org.gradle.api.internal.provider.DefaultProperty.get(DefaultProperty.java:157)
        at com.github.spotbugs.snom.SpotBugsReport.getDestination(SpotBugsReport.java:59)
        at com.github.spotbugs.snom.internal.SpotBugsHtmlReport_Decorated.getDestination(Unknown Source)
        at org.gradle.api.internal.tasks.properties.bean.AbstractNestedRuntimeBeanNode$BeanPropertyValue$1$1.create(AbstractNestedRuntimeBeanNode.java:80)
        at org.gradle.util.SingleMessageLogger.whileDisabled(SingleMessageLogger.java:467)
        at org.gradle.api.internal.tasks.properties.bean.AbstractNestedRuntimeBeanNode$BeanPropertyValue$1.get(AbstractNestedRuntimeBeanNode.java:76)
        at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:167)
        at org.gradle.api.internal.tasks.properties.bean.AbstractNestedRuntimeBeanNode$BeanPropertyValue.call(AbstractNestedRuntimeBeanNode.java:148)
        at org.gradle.util.GUtil.uncheckedCall(GUtil.java:461)
        at org.gradle.util.DeferredUtil.unpackNestableDeferred(DeferredUtil.java:64)
        at org.gradle.util.DeferredUtil.unpack(DeferredUtil.java:38)
        at org.gradle.api.internal.tasks.properties.FileParameterUtils.resolveOutputFilePropertySpecs(FileParameterUtils.java:109)
        at org.gradle.execution.plan.DefaultExecutionPlan$8$1.run(DefaultExecutionPlan.java:619)
        at org.gradle.execution.plan.DefaultExecutionPlan.withDeadlockHandling(DefaultExecutionPlan.java:679)
        at org.gradle.execution.plan.DefaultExecutionPlan.access$900(DefaultExecutionPlan.java:90)
        at org.gradle.execution.plan.DefaultExecutionPlan$8.visitOutputFileProperty(DefaultExecutionPlan.java:612)
        at org.gradle.api.internal.tasks.properties.annotations.AbstractOutputPropertyAnnotationHandler.visitPropertyValue(AbstractOutputPropertyAnnotationHandler.java:51)
        at org.gradle.api.internal.tasks.properties.bean.AbstractNestedRuntimeBeanNode.visitProperties(AbstractNestedRuntimeBeanNode.java:59)
        at org.gradle.api.internal.tasks.properties.bean.NestedRuntimeBeanNode.visitNode(NestedRuntimeBeanNode.java:42)
        at org.gradle.api.internal.tasks.properties.DefaultPropertyWalker.visitProperties(DefaultPropertyWalker.java:41)
        at org.gradle.api.internal.tasks.TaskPropertyUtils.visitProperties(TaskPropertyUtils.java:42)
        at org.gradle.execution.plan.DefaultExecutionPlan.resolveMutations(DefaultExecutionPlan.java:609)
        ... 10 more

I think the last error seems to be lack of report destination source (at com.github.spotbugs.snom.internal.SpotBugsHtmlReport_Decorated.getDestination(Unknown Source).

@KengoTODA
Copy link
Member

Thanks for updating information!
This is known issue, it seems that Android Gradle plugin deleted AndroidJavaCompile task 🤔

Their release note has no description about it, so I'm still not sure how we should fix this issue.
Do you have any idea about why they removed the task? 😭

One workaround, is that, apply the base plugin and create SpotBugsTask by your own. Then it won't touch AndroidJavaCompile class so it should work.

@henrychoi7
Copy link

Oh, I didn't know that was a known issue and I'm not sure why they removed AndroidJavaCompile task.. I also tried to find the relevant issue from Google's IssueTracker but, I couldn't find anything about why they removed the task except this.

I solved the problem above by creating my own task. Thank you again! 😄 I'm not very professional about Android Gradle plugin but, there must be a way to solve this issue to be native support for Android..

@seadowg
Copy link

seadowg commented Mar 24, 2020

One workaround, is that, apply the base plugin and create SpotBugsTask by your own. Then it won't touch AndroidJavaCompile class so it should work.

@KengoTODA do you have example of how to "create SpotBugsTask"? We're running into this issue but not quite sure how to apply the workaround! Excuse the lack of gradle skillz.

@kenyee
Copy link

kenyee commented May 19, 2020

@KengoTODA : FYI, AndroidJavaCompile has been totally removed. You can pin the spotbugsTask against the JavaCompile task instead. Verified it w/ the Android tools folks.

@kenyee
Copy link

kenyee commented May 19, 2020

Looks like a pretty simple change:

@kenyee
Copy link

kenyee commented May 19, 2020

I can do a PR but I don't see any dev readme on how to test/validate this plugin...

@davidburstromspotify
Copy link
Contributor

I already have a PR up for it: #252

@kenyee
Copy link

kenyee commented May 21, 2020

Nice...what's the hold up on getting the PR merged and released @KengoTODA ? Looks pretty straightforward...

@peter-budo
Copy link

Would really love to see this available. Could you share eta on release?

@bansan85
Copy link

bansan85 commented Apr 19, 2023

I can confirm that adding:

tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
    dependsOn 'assembleDebug'.
    classes = files("${project.buildDir}/intermediates/javac/variant")
}

makes following error disappear:

> Task :lib:compileJava FAILED
XXXX.java:5: error: package android.util does not exist
import android.util.Log;
                   ^
XXXX.java:22: error: cannot find symbol
    Log.e("tag", "message");
    ^
  symbol:   variable Log
  location: class AGenesis
2 errors

But instead, I have:

> Task :lib:spotbugsMain
Scanning archives (8 / 8)
2 analysis passes to performG [5s]
Pass 1: Analyzing classes (19 / 19) - 100% complete
Pass 2: Analyzing classes (6 / 6) - 100% complete
Done with analysis
The following classes needed for analysis were missing:
  android.util.Log
The following classes needed for analysis were missing:
  android.util.Log

@bansan85
Copy link

And to fix last error:

tasks.withType(com.github.spotbugs.snom.SpotBugsTask) { taski ->
    doFirst {
        taski.setAuxClassPaths(project.files(taski.getAuxClassPaths().getFiles(), project.android.getBootClasspath()))
    }
    dependsOn 'assembleDebug'.
    classes = files("${project.buildDir}/intermediates/javac/variant")
}

This makes pass spotbugs for my Android project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.