tbroyer / gradle-errorprone-plugin

Gradle plugin to use the error-prone compiler for Java
Apache License 2.0
366 stars 32 forks source link

error: plug-in not found: ErrorProne #85

Closed mattfbacon closed 8 months ago

mattfbacon commented 1 year ago

Similar to #52 , but I do have the line that they were missing.

Here's my build.gradle:

plugins {
    id 'com.android.application'
    id 'net.ltgt.errorprone' version '3.1.0'
}

android {
    compileSdk 33

    defaultConfig {
        applicationId "nz.felle.messageasebetter"
        minSdk 33
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_16
        targetCompatibility JavaVersion.VERSION_16
    }
    namespace 'nz.felle.messageasebetter'
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.preference:preference:1.2.0'

    annotationProcessor "com.uber.nullaway:nullaway:0.10.11"

    errorprone "com.google.errorprone:error_prone_core:2.20.0"
    errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"
}

import net.ltgt.gradle.errorprone.CheckSeverity

tasks.withType(JavaCompile) {
    options.errorprone {
        check("NullAway", CheckSeverity.ERROR)
        option("NullAway:AnnotatedPackages", "com.uber")
        enabled = true
    }
}

Running ./gradlew build gives

> Task :app:compileDebugJavaWithJavac FAILED
error: plug-in not found: ErrorProne
$ java --version
openjdk 17.0.8 2023-07-18
OpenJDK Runtime Environment (build 17.0.8+7)
OpenJDK 64-Bit Server VM (build 17.0.8+7, mixed mode)
$ ./gradlew --version

------------------------------------------------------------
Gradle 8.0
------------------------------------------------------------

Build time:   2023-02-13 13:15:21 UTC
Revision:     62ab9b7c7f884426cf79fbedcf07658b2dbe9e97

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.8 (Oracle Corporation 17.0.8+7)
OS:           Linux 6.4.6-arch1-1 amd64
coolderli commented 8 months ago

try to add apply(plugin = "net.ltgt.errorprone")

tbroyer commented 8 months ago

Thanks for the heads-up @coolderli, and sorry for the delay @mattfbacon (I probably was on vacation at the time). The issue is that the Android Gradle Plugin does not use standard Gradle source sets, so this plugin cannot setup annotationProcessor configurations to extend from the errorprone configuration; the compilation tasks are configured to use Error Prone but the dependency is not in the annotation processor path.

The solution is to declare Error Prone dependencies in the annotationProcessor (or make this configuration extend from the errorprone configuration) for each source set whose compilation task you enable Error Prone on.

Fwiw, this plugin had specific support for the AGP until version 3, where it was removed because the AGP API changed without a clear migration path (and I don't do android development myself). Nobody seems to have created an Android-specific plugin to add support on top of this plugin.