1

I am incorporating null away and error prone into my app and have added the following to my top-level build.gradle

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

subprojects {
    apply from: rootProject.file("gradle/nullaway.gradle")
}
...

then in the nullaway.gradle file I have

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

apply plugin: 'net.ltgt.errorprone'

if (this.name == 'javalib1' || this.name == 'javalib2') {
    apply plugin: 'java-library'

    dependencies {
        annotationProcessor deps.thirdparty.nullaway

        errorprone deps.thirdparty.error_prone
    }
} else {
    if (this.name == 'app') {
        apply plugin: 'com.android.application'
    } else {
        apply plugin: 'com.android.library'
    }

    dependencies {
        annotationProcessor deps.thirdparty.nullaway

        errorprone deps.thirdparty.error_prone
    }
}

tasks.withType(JavaCompile) {
    if (!name.toLowerCase().contains("test")) {
        options.compilerArgs += [
                "-Xep:NullAway:WARN",
                "-XepOpt:NullAway:AnnotatedPackages=com.mypackage",
                "-Xep:RestrictTo:WARN",
                "-XepExcludedPaths:.*/build/generated/.*"]
    }
}

With this setup whenever I try to build my app I get an exception

Caused by: java.lang.IllegalAccessError: tried to access class com.google.common.graph.BaseGraph from class com.google.common.graph.Traverser
    at com.google.common.graph.Traverser.forTree(Traverser.java:134)
    at dagger.internal.codegen.ValidationReport.<clinit>(ValidationReport.java:63)
    at dagger.internal.codegen.InjectValidator.validateMembersInjectionType(InjectValidator.java:257)
    at dagger.internal.codegen.InjectBindingRegistryImpl.tryRegisterMembersInjectedType(InjectBindingRegistryImpl.java:269)
    at dagger.internal.codegen.InjectBindingRegistryImpl.tryRegisterMembersInjectedType(InjectBindingRegistryImpl.java:253)
    at dagger.internal.codegen.InjectProcessingStep$1.visitVariableAsField(InjectProcessingStep.java:67)
    at dagger.internal.codegen.InjectProcessingStep$1.visitVariableAsField(InjectProcessingStep.java:57)
    at com.sun.tools.javac.code.Symbol$VarSymbol.accept(Symbol.java:1550)
    at dagger.internal.codegen.InjectProcessingStep.process(InjectProcessingStep.java:56)
    at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:330)
    at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:181)

I check the notes and I am using dagger version 2.16 and as you can see I have the exclude for build/generated files. What am I missing?

Zachary Sweigart
  • 1,051
  • 9
  • 23
  • Have you tried just removing the NullAway config (`annotationProcessor deps.thirdparty.nullaway` and compiler args) to see if that fixes the problem? Based on the above I can't immediately see that NullAway is at fault. – msridhar Sep 07 '18 at 19:59
  • Removing null away and the first two compiler args for null away leaves me with the same exception so it seems error prone isn't working well with dagger – Zachary Sweigart Sep 07 '18 at 20:38
  • If you have a repro with just errorprone, you can file an issue on https://github.com/tbroyer/gradle-errorprone-plugin and see if you can get any help there. Probably it would help to make a small repro case available on GitHub – msridhar Sep 07 '18 at 20:50

0 Answers0