在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):tbroyer/gradle-errorprone-plugin开源软件地址(OpenSource Url):https://github.com/tbroyer/gradle-errorprone-plugin开源编程语言(OpenSource Language):Kotlin 95.1%开源软件介绍(OpenSource Introduction):gradle-errorprone-pluginThis plugin configures RequirementsThis plugin requires using at least Gradle 5.2. While JDK 8 is supported, it is recommended to use at least a JDK 9 compiler. See note below about JDK 8 support. Usageplugins {
id("net.ltgt.errorprone") version "<plugin version>"
} Note: snippets in this guide use features from the latest Gradle version, so beware if copy/pasting. This plugin creates a configuration named Error Prone needs to be added as a dependency in this configuration: repositories {
mavenCentral()
}
dependencies {
errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
} CAUTION: Using a dynamic or changing version for Error Prone,
such as Error Prone can then be configured on the tasks.withType(JavaCompile).configureEach {
options.errorprone.disableWarningsInGeneratedCode = true
} with Kotlin DSLimport net.ltgt.gradle.errorprone.errorprone
tasks.withType<JavaCompile>().configureEach {
options.errorprone.disableWarningsInGeneratedCode.set(true)
} and can also be disabled altogether: tasks.named("compileTestJava").configure {
options.errorprone.enabled = false
} with Kotlin DSLtasks.named<JavaCompile>("compileTestJava") {
options.errorprone.isEnabled.set(false)
} Note that this plugin only enables Error Prone on tasks for source sets
(i.e. tasks.register("compileCustom", JavaCompile) {
source "src/custom/"
include "**/*.java"
classpath = configurations.custom
sourceCompatibility = "8"
targetCompatibility = "8"
destinationDir = file("$buildDir/classes/custom")
// Error Prone must be available in the annotation processor path
options.annotationProcessorPath = configurations.errorprone
// Enable Error Prone
options.errorprone.enabled = true
// It can then be configured for the task
options.errorprone.disableWarningsInGeneratedCode = true
} with Kotlin DSLtasks.register<JavaCompile>("compileCustom") {
source("src/custom/")
include("**/*.java")
classpath = configurations["custom"]
sourceCompatibility = "8"
targetCompatibility = "8"
destinationDir = file("$buildDir/classes/custom")
// Error Prone must be available in the annotation processor path
options.annotationProcessorPath = configurations["errorprone"]
// Enable Error Prone
options.errorprone.isEnabled.set(true)
// It can then be configured for the task
options.errorprone.disableWarningsInGeneratedCode.set(true)
} JDK 8 supportError Prone requires at least a JDK 9 compiler.
When using a JDK 8 compiler, you can configure a dependency on the Error Prone javac in the dependencies {
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
} and the plugin will configure the Starting with Gradle 6.7, you can configure Alternatively, or for previous versions of Gradle, you can configure tasks.withType(JavaCompile).configureEach {
options.fork(javaHome: project.getProperty("jdk11home"))
} with Kotlin DSLtasks.withType<JavaCompile>().configureEach {
options.fork = true
options.forkOptions.javaHome = project.getProperty("jdk11home")
} The plugin will try to detect those cases and won't configure the bootstrap classpath in this case,
but to play safe it will actually ignore any task that forks and defines either a If you need it, you can configure the bootstrap classpath manually for those tasks that the plugin would have skipped: someTask.configure {
// …
inputs.files(configurations.errorproneJavac).withNormalizer(ClasspathNormalizer)
doFirst {
options.forkOptions.jvmArgs += "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}"
}
} with Kotlin DSLsomeTask.configure {
// …
inputs.files(configurations.errorproneJavac).withNormalizer(ClasspathNormalizer::class)
doFirst {
options.forkOptions.jvmArgs.add("-Xbootclasspath/p:${configurations["errorproneJavac"].asPath}")
}
} (if you're using JDK 16+ supportStarting with JDK 16, due to JEP 396: Strongly Encapsulate JDK Internals by Default,
The plugin will automatically use a forking compiler and pass the necessary JVM arguments whenever it detects such a JDK is being used and ErrorProne is enabled. That detection will only take into account the toolchain used by the Custom Error Prone checksCustom Error Prone checks can be added to the dependencies {
errorprone("com.uber.nullaway:nullaway:$nullawayVersion")
} or alternatively to the dependencies {
annotationProcessor("com.google.guava:guava-beta-checker:$betaCheckerVersion")
} and can then be configured on the tasks; for example: tasks.withType(JavaCompile).configureEach {
options.errorprone {
option("NullAway:AnnotatedPackages", "net.ltgt")
}
}
tasks.named("compileJava").configure {
// The check defaults to a warning, bump it up to an error for the main sources
options.errorprone.error("NullAway")
} with Kotlin DSLtasks.withType<JavaCompile>().configureEach {
options.errorprone {
option("NullAway:AnnotatedPackages", "net.ltgt")
}
}
tasks.named("compileJava", JavaCompile::class) {
// The check defaults to a warning, bump it up to an error for the main sources
options.errorprone.error("NullAway")
} ConfigurationAs noted above, this plugin adds an In a import net.ltgt.gradle.errorprone.errorprone PropertiesPlease note that all properties are lazy,
so while you can use
Methods
A check severity can take values: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论