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

Gradle error when adding NullAway 0.1.7 to Android projects #48

Closed
yaroslav-shlapak opened this issue Oct 27, 2017 · 6 comments
Closed

Comments

@yaroslav-shlapak
Copy link

I'm getting the gradle build error when adding NullAway version 0.1.7 to different projects in Android Studio 3.0 and gradle plugin version 3.0.0.

Commenting out

annotationProcessor "com.uber.nullaway:nullaway:0.1.7"

leads to successful build.

Project level build.gradle:

buildscript {
...
    repositories {
        jcenter()
        google()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.11"
    }
}
...

App level build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'net.ltgt.errorprone'

project.ext {
    supportLibraryVersion = "25.4.0"
    daggerVersion = "2.11"
    butterKnifeVersion = "8.7.0"
    rxJavaVersion = "2.1.0"
    rxAndroidVersion = "2.0.1"
    timberVersion = "4.5.1"
    lifecycleVersion = "1.0.0-alpha4"
    priorityJobQueueVersion = "2.0.1"
    playServicesVersion = "11.4.2"
    retrofitVersion = "2.1.0"
    okHttpVersion = "3.4.1"
    rxRelayVersion = "2.0.0"
    rxLintVersion = "1.6"
}

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "com.example.offline"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation "com.android.support:appcompat-v7:$project.supportLibraryVersion"

    // Dagger core
    annotationProcessor "com.google.dagger:dagger-compiler:$project.daggerVersion"
    implementation "com.google.dagger:dagger:$project.daggerVersion"

    // Dagger Android
    annotationProcessor "com.google.dagger:dagger-android-processor:$project.daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$project.daggerVersion"

    // ButterKnife
    implementation "com.jakewharton:butterknife:$project.butterKnifeVersion"
    annotationProcessor "com.jakewharton:butterknife-compiler:$project.butterKnifeVersion"

    // ReactiveX
    implementation "io.reactivex.rxjava2:rxjava:$project.rxJavaVersion"
    implementation "io.reactivex.rxjava2:rxandroid:$project.rxAndroidVersion"

    // Timber
    implementation "com.jakewharton.timber:timber:$project.timberVersion"

    // Priority Job Queue
    implementation "com.birbit:android-priority-jobqueue:$project.priorityJobQueueVersion"

    //GCM Network Manager
    implementation "com.google.android.gms:play-services-gcm:$project.playServicesVersion"

    // RecyclerView
    implementation "com.android.support:recyclerview-v7:$project.supportLibraryVersion"

    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:$project.retrofitVersion"

    // GSON Converter
    implementation "com.squareup.retrofit2:converter-gson:$project.retrofitVersion"

    // OkHttp Logging Interceptor
    implementation "com.squareup.okhttp3:okhttp:$project.okHttpVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$project.okHttpVersion"

    // Room Database
    implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
    implementation "android.arch.persistence.room:rxjava2:$rootProject.roomVersion"
    annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"

    // Lifecycle
    implementation "android.arch.lifecycle:runtime:$project.lifecycleVersion"
    implementation "android.arch.lifecycle:extensions:$project.lifecycleVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$project.lifecycleVersion"

    // RxRelay
    implementation "com.jakewharton.rxrelay2:rxrelay:$project.rxRelayVersion"

    // RxLint
    implementation "nl.littlerobots.rxlint:rxlint:$project.rxLintVersion"

    //Nullaway
    annotationProcessor "com.uber.nullaway:nullaway:0.1.7"
    compileOnly "com.google.code.findbugs:jsr305:3.0.2"
    errorprone "com.google.errorprone:error_prone_core:2.1.2"

}

tasks.withType(JavaCompile) {
    if (!name.toLowerCase().contains("test")) {
        options.compilerArgs += ["-Xep:NullAway:ERROR", "-XepOpt:NullAway:AnnotatedPackages=com.example"]
    }
}

Error stacktrace

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
	at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
	at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
	at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
	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:248)
	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:241)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
	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:625)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
	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: org.gradle.internal.UncheckedException: java.lang.reflect.InvocationTargetException
	at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:63)
	at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:40)
	at net.ltgt.gradle.errorprone.ErrorProneCompiler.execute(ErrorProneCompiler.java:75)
	at net.ltgt.gradle.errorprone.ErrorProneCompiler.execute(ErrorProneCompiler.java:24)
	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:99)
	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:52)
	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:37)
	at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
	at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
	at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:39)
	at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:24)
	at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:204)
	at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:130)
	at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:95)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:179)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:135)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:122)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
	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.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
	... 28 more
Caused by: java.lang.reflect.InvocationTargetException
	at net.ltgt.gradle.errorprone.ErrorProneCompiler.execute(ErrorProneCompiler.java:63)
	... 50 more
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/openjdk/source/tree/Tree
	at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:158)
	at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96)
	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90)
	at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:137)
	at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:108)
	at com.google.errorprone.ErrorProneCompiler.run(ErrorProneCompiler.java:118)
	at com.google.errorprone.ErrorProneCompiler.compile(ErrorProneCompiler.java:65)
	... 51 more
Caused by: java.lang.NoClassDefFoundError: org/openjdk/source/tree/Tree
	at com.google.googlejavaformat.java.filer.FormattingFiler.<init>(FormattingFiler.java:37)
	at com.google.googlejavaformat.java.filer.FormattingFiler.<init>(FormattingFiler.java:42)
	at dagger.internal.codegen.ComponentProcessor.initSteps(ComponentProcessor.java:66)
	at dagger.shaded.auto.common.BasicAnnotationProcessor.init(BasicAnnotationProcessor.java:119)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:675)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:774)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:869)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2200(JavacProcessingEnvironment.java:108)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1204)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1313)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1267)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:943)
	at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100)
	at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142)
	... 57 more
Caused by: java.lang.ClassNotFoundException: org.openjdk.source.tree.Tree
	... 71 more
@msridhar
Copy link
Collaborator

This may be the same as #25. @hzsweers did you ever find a fix for this? @kageiit any suggestions?

@ZacSweers
Copy link
Contributor

I didn't find a fix yet

@msridhar
Copy link
Collaborator

msridhar commented Oct 27, 2017

Ah, I know what this is. The problem is that an old version of Google Java Format didn't shade its internal javac correctly (see google/google-java-format#169). This is fixed as of GJF 1.4. @yaroslav-shlapak can you change your // Dagger core section to the following and see if that fixes it?

    // Dagger core
    annotationProcessor ["com.google.dagger:dagger-compiler:$project.daggerVersion", "com.google.googlejavaformat:google-java-format:1.4"]
    implementation "com.google.dagger:dagger:$project.daggerVersion"

@msridhar
Copy link
Collaborator

Alternately, I think updating daggerVersion to 2.12 should fix this problem

@yaroslav-shlapak
Copy link
Author

@msridhar by this

annotationProcessor ["com.google.dagger:dagger-compiler:$project.daggerVersion", "com.google.googlejavaformat:google-java-format:1.4"]

did you mean something like this

configurations.all {
     resolutionStrategy {
         force "com.google.googlejavaformat:google-java-format:1.4"
     }
}

to forcefully resolve versions conflict?

I've tried solutiions with dagger version 2.12 and forced dependencies resolving - they both work.

Dependencies tree check:

+--- com.google.dagger:dagger-compiler:2.11
| +--- com.google.googlejavaformat:google-java-format:1.3

and

+--- com.google.dagger:dagger-compiler:2.12
| +--- com.google.googlejavaformat:google-java-format:1.4

Thank you for fast and helpful response!:+1:
Hope NullAway will help to make my apps more robust.

@msridhar
Copy link
Collaborator

The only disadvantage with forcing dependencies is it will force a downgrade if/when other libs pull in an even more recent version of GJF (1.5 has been released). If you just add a dependence on 1.4 that should lead to the upgrade but not the downgrade. All that said, in this case probably bumping to Dagger 2.12 is the best solution, if that works for you.

Please let us know if you have other issues!

msridhar added a commit that referenced this issue Oct 30, 2017
Whenever NullAway runs, it must be loaded via Error Prone. Hence, I believe that the Error Prone Check APIs should always be available. Making the errorProneCheckApi a compileOnly dependence should reduce the size of the annotation processor classpath in some cases, which could speed up builds and avoid some incompatibilities like in #48.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants