{"id":13733433,"url":"https://github.com/tbroyer/gradle-errorprone-plugin","last_synced_at":"2025-05-08T09:32:06.819Z","repository":{"id":43278898,"uuid":"125682893","full_name":"tbroyer/gradle-errorprone-plugin","owner":"tbroyer","description":"Gradle plugin to use the error-prone compiler for Java","archived":false,"fork":false,"pushed_at":"2025-04-25T13:32:38.000Z","size":844,"stargazers_count":379,"open_issues_count":4,"forks_count":33,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-25T14:43:43.964Z","etag":null,"topics":["error-prone","errorprone","gradle-plugin","java"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tbroyer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-03-18T01:24:38.000Z","updated_at":"2025-04-25T13:32:35.000Z","dependencies_parsed_at":"2023-01-31T09:15:29.170Z","dependency_job_id":"1ec31d7c-655a-4258-9433-9c461471fa7f","html_url":"https://github.com/tbroyer/gradle-errorprone-plugin","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbroyer%2Fgradle-errorprone-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbroyer%2Fgradle-errorprone-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbroyer%2Fgradle-errorprone-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbroyer%2Fgradle-errorprone-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbroyer","download_url":"https://codeload.github.com/tbroyer/gradle-errorprone-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253036601,"owners_count":21844245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-prone","errorprone","gradle-plugin","java"],"created_at":"2024-08-03T03:00:43.013Z","updated_at":"2025-05-08T09:32:05.076Z","avatar_url":"https://github.com/tbroyer.png","language":"Kotlin","funding_links":[],"categories":["Plugins"],"sub_categories":["Code quality"],"readme":"# gradle-errorprone-plugin\n\nThis plugin configures `JavaCompile` tasks to use [Error Prone].\n\n[Error Prone]: https://errorprone.info/\n\n## Requirements\n\nThis plugin requires using at least Gradle 6.8.\n\nWhile JDK 8 is supported, it is recommended to use at least a JDK 9 compiler.\nSee [note below](#jdk-8-support) about JDK 8 support.\n\nThere's no specific support for the [Android Gradle Plugin](https://developer.android.com/build).\nRead on to better understand what you need to do to use both plugins together.\nSpecifically, note that _source sets_ below are only about [standard Gradle source sets for JVM projects](https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_source_sets), not [Android source sets](https://developer.android.com/build#sourcesets), so anything done by the plugin based on source sets won't be done at all for Android projects.\n\n## Usage\n\n```kotlin\nplugins {\n    id(\"net.ltgt.errorprone\") version \"\u003cplugin version\u003e\"\n}\n```\n\nThis plugin creates a configuration named `errorprone`,\nand configures the `\u003csourceSet\u003eAnnotationProcessor` configuration for each source set to extend it.\nThis allows configuring Error Prone dependencies from a single place.\n\nError Prone needs to be added as a dependency in this configuration:\n```kotlin\nrepositories {\n    mavenCentral()\n}\ndependencies {\n    errorprone(\"com.google.errorprone:error_prone_core:$errorproneVersion\")\n}\n```\n\n\u003e [!CAUTION]\n\u003e Using a dynamic or changing version for Error Prone,\n\u003e such as `latest.release` or `2.+`,\n\u003e means that your build could fail at any time,\n\u003e if a new version of Error Prone adds or enables new checks that your code would trigger.\n\nError Prone can then be [configured](#configuration) on the `JavaCompile` tasks:\n```kotlin\nimport net.ltgt.gradle.errorprone.errorprone\n\ntasks.withType\u003cJavaCompile\u003e().configureEach {\n    options.errorprone.disableWarningsInGeneratedCode.set(true)\n}\n```\n\u003cdetails\u003e\n\u003csummary\u003ewith Groovy DSL\u003c/summary\u003e\n\n```gradle\ntasks.withType(JavaCompile).configureEach {\n    options.errorprone.disableWarningsInGeneratedCode = true\n}\n```\n\n\u003c/details\u003e\n\nand can also be disabled altogether:\n```kotlin\ntasks {\n    compileTestJava {\n        options.errorprone.isEnabled.set(false)\n    }\n}\n```\n\u003cdetails\u003e\n\u003csummary\u003ewith Groovy DSL\u003c/summary\u003e\n\n```gradle\ntasks {\n    compileTestJava {\n        options.errorprone.enabled = false\n    }\n}\n```\n\n\u003c/details\u003e\n\nNote that this plugin only enables Error Prone on tasks for source sets\n(i.e. `compileJava` for the `main` source set, `compileTestJava` for the `test` source set,\nand `compileIntegTestJava` for a custom `integTest` source set).\n\n\u003cdetails\u003e\n\u003csummary\u003eIf you're creating custom compile tasks,\nthen you'll have to configure them manually to enable Error Prone\u003c/summary\u003e\n\n```kotlin\nval annotationProcessorCustom = configurations.resolvable(\"annotationProcessorCustom\") {\n    extendsFrom(configurations.errorprone.get())\n}\ntasks.register\u003cJavaCompile\u003e(\"compileCustom\") {\n    source(\"src/custom/\")\n    include(\"**/*.java\")\n    classpath = configurations[\"custom\"]\n    sourceCompatibility = \"8\"\n    targetCompatibility = \"8\"\n    destinationDir = file(\"$buildDir/classes/custom\")\n\n    // Error Prone must be available in the annotation processor path\n    options.annotationProcessorPath = annotationProcessorCustom.get()\n    // Enable Error Prone\n    options.errorprone.isEnabled = true\n    // It can then be configured for the task\n    options.errorprone.disableWarningsInGeneratedCode = true\n}\n```\n\u003cdetails\u003e\n\u003csummary\u003ewith Groovy DSL\u003c/summary\u003e\n\n```gradle\ndef annotationProcessorCustom = configurations.resolvable(\"annotationProcessorCustom\") {\n    extendsFrom(configurations.errorprone)\n}\ntasks.register(\"compileCustom\", JavaCompile) {\n    source \"src/custom/\"\n    include \"**/*.java\"\n    classpath = configurations.custom\n    sourceCompatibility = \"8\"\n    targetCompatibility = \"8\"\n    destinationDir = file(\"$buildDir/classes/custom\")\n\n    // Error Prone must be available in the annotation processor path\n    options.annotationProcessorPath = annotationProcessorCustom\n    // Enable Error Prone\n    options.errorprone.enabled = true\n    // It can then be configured for the task\n    options.errorprone.disableWarningsInGeneratedCode = true\n}\n```\n\n\u003c/details\u003e\n\u003c/details\u003e\n\n## JDK 8 support\n\nError Prone requires at least a JDK 9 compiler.\nWhen using a JDK 8 compiler, the plugin will configure the `JavaCompile` tasks to [use a forking compiler][CompileOptions.fork]\nand will override the compiler by prepending the Error Prone javac to the bootstrap classpath\n(using a `-Xbootclasspath/p:` [JVM argument][BaseForkOptions.getJvmArgs]).\n\nYou can [configure `JavaCompile` tasks][gradle-toolchains] to use a specific JDK compiler,\nindependently of the JDK used to run Gradle itself.\nThe plugin will use the toolchain version, if any is specified, to configure the task.\nThis allows you to enforce compilation with JDK 11 while running Gradle with JDK 8.\n(In case you would want to enforce compilation with JDK 8 instead,\nthe plugin would detect it and properly configure the bootstrap classpath as described above)\n\nNote that the plugin will ignore any task that forks and defines either [a `javaHome`][ForkOptions.setJavaHome] or [an `executable`][ForkOptions.setExecutable],\nand thus won't configure the bootstrap classpath if you're e.g. running Gradle with a more recent JDK and forking the compilation tasks to use JDK 8.\n\n[gradle-toolchains]: https://docs.gradle.org/current/userguide/toolchains.html\n[CompileOptions.fork]: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html#org.gradle.api.tasks.compile.CompileOptions:fork\n[BaseForkOptions.getJvmArgs]: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/BaseForkOptions.html#getJvmArgs--\n[ForkOptions.setJavaHome]: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/ForkOptions.html#setJavaHome-java.io.File-\n[ForkOptions.setExecutable]: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/ForkOptions.html#setExecutable-java.lang.String-\n\n## JDK 16+ support\n\nStarting with JDK 16, due to [JEP 396: Strongly Encapsulate JDK Internals by Default][jep396],\n`--add-opens` and `--add-exports` arguments need to be passed to the compiler's JVM.\n\nThe plugin will automatically [use a forking compiler][CompileOptions.fork]\nand pass the necessary [JVM arguments][BaseForkOptions.getJvmArgs]\nwhenever it detects such a JDK is being used and ErrorProne is enabled\n(unless the Gradle daemon's JVM already was given the appropriate options [through `org.gradle.jvmargs`][org.gradle.jvmargs]).\n\nThat detection will only take into account the [toolchain][gradle-toolchains] used by the `JavaCompile` task,\nor the JDK used to run Gradle in case no toolchain is being used.\nThe plugin will ignore any task that forks and defines either [a `javaHome`][ForkOptions.setJavaHome] or [an `executable`][ForkOptions.setExecutable],\nand thus won't configure the JVM arguments if you're e.g. running Gradle with an older JDK and forking the compilation tasks to use JDK 17.\n\nNote that the plugin also configures the JVM arguments for any JDK above version 9 to silence related warnings,\nbut they will then only be used if the task is explicitly configured for forking\n(or if the configured toolchain is incompatible with the JDK used to run Gradle, which will then implicitly fork a compiler daemon).\n\n[jep396]: https://openjdk.java.net/jeps/396\n[org.gradle.jvmargs]: https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory\n\n## Android Gradle Plugin support\n\nAs noted above, this plugin won't have much effect when used in conjunction with the AGP rather than, say, Gradle's built-in Java plugins.\n\nIt will then:\n* create the `errorprone` configuration, but won't wire it to any other configuration, and by extension to any compilation task\n* enhance `JavaCompile` tasks with the `errorprone` extension, but keep ErrorProne disabled by default (it would fail otherwise, as ErrorProne won't be on the processor path)\n\nYou'll thus have to somehow:\n* put ErrorProne on the processor path of the `JavaCompile` tasks\n* enable ErrorProne on the `JavaCompile` tasks\n* configure `isCompilingTestOnlyCode` for compilation tasks for test variants (this changes the behavior of some checks)\n\nThis could (and should) be done by a plugin, so if you have deep knowledge of the [AGP APIs](https://developer.android.com/build/extend-agp) and how to idiomatically integrate Error Prone within Android builds, please make such a plugin and I'll link to it here for others to use.\n\n## Custom Error Prone checks\n\n[Custom Error Prone checks][custom checks] can be added to the `errorprone` configuration too:\n```kotlin\ndependencies {\n    errorprone(\"com.uber.nullaway:nullaway:$nullawayVersion\")\n}\n```\nor alternatively to the `\u003csourceSet\u003eAnnotationProcessor` configuration,\nif they only need to be enabled for a given source set:\n```kotlin\ndependencies {\n    annotationProcessor(\"com.google.guava:guava-beta-checker:$betaCheckerVersion\")\n}\n```\nand can then be configured on the tasks; for example:\n```kotlin\ntasks.withType\u003cJavaCompile\u003e().configureEach {\n    options.errorprone {\n        option(\"NullAway:AnnotatedPackages\", \"net.ltgt\")\n    }\n}\ntasks.compileJava {\n    // The check defaults to a warning, bump it up to an error for the main sources\n    options.errorprone.error(\"NullAway\")\n}\n```\n\u003cdetails\u003e\n\u003csummary\u003ewith Groovy DSL\u003c/summary\u003e\n\n```gradle\ntasks.withType(JavaCompile).configureEach {\n    options.errorprone {\n        option(\"NullAway:AnnotatedPackages\", \"net.ltgt\")\n    }\n}\ntasks.compileJava {\n    // The check defaults to a warning, bump it up to an error for the main sources\n    options.errorprone.error(\"NullAway\")\n}\n```\n\n\u003c/details\u003e\n\n\u003e [!NOTE]\n\u003e These examples use NullAway.\n\u003e Note that I made [a companion plugin][gradle-nullaway-plugin] specifically to surface NullAway options as Gradle DSL properties.\n\n[custom checks]: https://errorprone.info/docs/plugins\n[gradle-nullaway-plugin]: https://github.com/tbroyer/gradle-nullaway-plugin\n\n## Configuration\n\nAs noted above, this plugin adds an `errorprone` extension to the `JavaCompile.options`.\nIt can be configured either as a property (`options.errorprone.xxx`)\nor script block (`options.errorprone { … }`).\n\nIn a `*.gradle.kts` script, the Kotlin extensions need to be imported:\n```kotlin\nimport net.ltgt.gradle.errorprone.errorprone\n```\n\n### Properties\n\n_Please note that all properties are [lazy](https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_properties)._\n\n| Property | Description\n| :------- | :----------\n| `isEnabled`                      | (`enabled` with Groovy DSL) Allows disabling Error Prone altogether for the task. Error Prone will still be in the annotation processor path, but `-Xplugin:ErrorProne` won't be passed as a compiler argument. Defaults to `true` for source set tasks, `false` otherwise.\n| `disableAllChecks`               | Disable all Error Prone checks; maps to `-XepDisableAllChecks`. This will be the first argument, so checks can then be re-enabled on a case-by-case basis. Defaults to `false`.\n| `disableAllWarnings`             | Maps to `-XepDisableAllWarnings` (since ErrorProne 2.4.0). Defaults to `false`.\n| `allErrorsAsWarnings`            | Maps to `-XepAllErrorsAsWarnings`. Defaults to `false`.\n| `allDisabledChecksAsWarnings`    | Enables all Error Prone checks, checks that are disabled by default are enabled as warnings; maps to `-XepDisabledChecksAsWarnings`. Defaults to `false`.\n| `disableWarningsInGeneratedCode` | Disables warnings in classes annotated with `javax.annotation.processing.Generated` or `@javax.annotation.Generated`; maps to `-XepDisableWarningsInGeneratedCode`. Defaults to `false`.\n| `ignoreUnknownCheckNames`        | Maps to `-XepIgnoreUnknownCheckNames`. Defaults to `false`.\n| `ignoreSuppressionAnnotations`   | Maps to `-XepIgnoreSuppressionAnnotations` (since Error Prone 2.3.3). Defaults to `false`.\n| `isCompilingTestOnlyCode`        | (`compilingTestOnlyCode` with Groovy DSL) Maps to `-XepCompilingTestOnlyCode`. Defaults to `false`. (defaults to `true` for a source set inferred as a test source set)\n| `excludedPaths`                  | A regular expression pattern (as a string) of file paths to exclude from Error Prone checking; maps to `-XepExcludedPaths`. Defaults to `null`.\n| `checks`                         | A map of check name to `CheckSeverity`, to configure which checks are enabled or disabled, and their severity; maps each entry to `-Xep:\u003ckey\u003e:\u003cvalue\u003e`, or `-Xep:\u003ckey\u003e` if the value is `CheckSeverity.DEFAULT`. Defaults to an empty map.\n| `checkOptions`                   | A map of check options to their value; maps each entry to `-XepOpt:\u003ckey\u003e=\u003cvalue\u003e`. Use an explicit `\"true\"` value for a boolean option. Defaults to an empty map.\n| `errorproneArgs`                 | Additional arguments passed to Error Prone. Defaults to an empty list.\n| `errorproneArgumentProviders`    | A list of [`CommandLineArgumentProvider`] for additional arguments passed to Error Prone. Defaults to an empty list.\n\n[`CommandLineArgumentProvider`]: https://docs.gradle.org/current/javadoc/org/gradle/process/CommandLineArgumentProvider.html\n\n### Methods\n\n| Method | Description\n| :----- | :----------\n| `enable(checkNames...)`           | Adds checks with their default severity. Useful in combination with `disableAllChecks` to selectively re-enable checks. Equivalent to `check(checkName, CheckSeverity.DEFAULT)` for each check name.\n| `disable(checkNames...)`          | Disable checks. Equivalent to `check(checkName, CheckSeverity.OFF)` for each check name.\n| `warn(checkNames...)`             | Adds checks with warning severity. Equivalent to `check(checkName, CheckSeverity.WARNING)` for each check name.\n| `error(checkNames...)`            | Adds checks with error severity. Equivalent to `check(checkName, CheckSeverity.ERROR)` for each check name.\n| `check(checkName to severity...)` | (Kotlin DSL only) Adds pairs of check name to severity. Equivalent to `checks.put(first, second)` for each pair.\n| `check(checkName, severity)`      | Adds a check with a given severity. The severity can be passed as a provider for lazy configuration. Equivalent to `checks.put(checkName, severity)`.\n| `option(optionName)`              | Enables a boolean check option. Equivalent to `option(checkName, true)`.\n| `option(optionName, value)`       | Adds a check option with a given value. Value can be a boolean or a string, or a provider of string. Equivalent to `checkOptions.put(name, value)`.\n\nA check severity can take values: `DEFAULT`, `OFF`, `WARN`, or `ERROR`.  \nNote that the `net.ltgt.gradle.errorprone.CheckSeverity` needs to be `import`ed into your build scripts (see examples above).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbroyer%2Fgradle-errorprone-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbroyer%2Fgradle-errorprone-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbroyer%2Fgradle-errorprone-plugin/lists"}