4

I am trying to setup error prone using gradle, however everything ive tried gives me some kind of error:

To test I have setup a simple hello world java program using gradle, which without error prone compiles fine. Then I read: https://github.com/tbroyer/gradle-errorprone-plugin found from the install guide and tried this in the build.gradle:

plugins {
    id 'java'
    id("net.ltgt.errorprone") version "2.3.3"
}

group 'test'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    errorprone("com.google.errorprone:error_prone_core:2.3.3")

}

This gave me this error:

Plugin [id: 'net.ltgt.errorprone', version: '2.3.3'] was not found in any of the following sources:

Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:2.3.3')
  Searched in the following repositories:
    Gradle Central Plugin Repository

I changed 2.3.3 to latest.version and got the same error

Then I found this https://plugins.gradle.org/plugin/net.ltgt.errorprone and tried version number 0.8.1. I need to be able to use java11 so can't use gradle 4.x as far as I understand.

Also if anybody knows of an actual repository that has used error prone with gradle that I could look at I would be very grateful :)

My gradle wrapper properties is set to use gradle version 5.4.1

Ben
  • 41
  • 1
  • 3
  • The gradle build file you posted has no sign of anything related to errorprone. – JB Nizet Jul 10 '19 at 17:14
  • But given that the latest version of the plugin is 0.8.1, I'm not surprised it can't find the version 2.3.3. – JB Nizet Jul 10 '19 at 17:18
  • OK, so you're using version 2.3.3 of the plugin, but the latest version is 0.8.1. And you have a missing double quote at the beginning of the version, making the build file incorrect. – JB Nizet Jul 10 '19 at 17:20
  • ah sorry, added now, I tried 0.8.1 and got ```Could not find com.google.errorprone:error_prone_core:0.8.1. Searched in the following locations: - https://repo.maven.apache.org/maven2/com/google/errorprone/error_prone_core/0.8.1/error_prone_core-0.8.1.pom - https://repo.maven.apache.org/maven2/com/google/errorprone/error_prone_core/0.8.1/error_prone_core-0.8.1.jar Required by: project :``` Also tried latest.release for the version number and got the original error (except the 2.3.3 was swapped for latest.release in the error message) – Ben Jul 10 '19 at 17:20
  • 1
    You need to realize that there are two different versions involved here: the version of com.google.errorprone:error_prone_core (2.3.3), and the version of the errorprone gradle plugin (net.ltgt.errorprone): 0.8.1. Don't use the same version for both, since those are different things. – JB Nizet Jul 10 '19 at 17:23
  • Ah thankyou, fixed. – Ben Jul 10 '19 at 17:27

1 Answers1

4

Solved as below

  1. Add Gradle plugin to build.gradle file
plugins {
    id("net.ltgt.errorprone") version "1.1.0"
}

Release versions

  1. Add dependency to error_prone_core in build.gradle file
dependencies {
    errorprone("com.google.errorprone:error_prone_core:2.3.3")
}

Releases
3. Build project, this will add errorprone configuration namespace
4. If you are using java-8, need to add additional dependency too.

errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")

along with dependency in step-2.
5. you can customize/enable/disable it by tasks

tasks.withType(JavaCompile).configureEach {
    options.errorprone.disableWarningsInGeneratedCode = true
    options.errorprone.enabled = false // change it to true to enable
}

Note: As mentioned in OP comment by @jb-nizet, gralde plugin and error_prone_core has different versions and independent release cycles.

my build.gradle file

buildscript {
    ext{
        errorproneVersion = '2.3.3'
    }
    repositories {
        mavenLocal()
        mavenCentral()
    }
}

plugins {
    id "java"
    id("net.ltgt.errorprone") version "1.1.0"
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
    errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}

tasks.withType(JavaCompile).configureEach {
    options.errorprone.disableWarningsInGeneratedCode = true
    options.errorprone.enabled = false
}

Ref

Github-error-prone

dkb
  • 4,389
  • 4
  • 36
  • 54
  • Hi. A "newbie" question. How do I see the results of error-prone? I did a "./gradlew build" but I don't see anything extra/new in regards to error-prone. I went to both links you shared and could not find a "see the results magic" examples. – granadaCoder Oct 11 '22 at 13:50