在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):kelloggm/checkerframework-gradle-plugin开源软件地址(OpenSource Url):https://github.com/kelloggm/checkerframework-gradle-plugin开源编程语言(OpenSource Language):Groovy 96.6%开源软件介绍(OpenSource Introduction):Gradle Checker Framework PluginThis plugin configures DownloadAdd the following to your plugins {
// Checker Framework pluggable type-checking
id 'org.checkerframework' version '0.6.12'
}
apply plugin: 'org.checkerframework' The ConfigurationConfiguring which checkers to useThe For example, using Groovy syntax in a checkerFramework {
checkers = [
'org.checkerframework.checker.nullness.NullnessChecker',
'org.checkerframework.checker.units.UnitsChecker'
]
} The same example, using Kotlin syntax in a // In Kotlin, you need to import CheckerFrameworkExtension explicitly:
import org.checkerframework.gradle.plugin.CheckerFrameworkExtension
configure<CheckerFrameworkExtension> {
checkers = listOf(
"org.checkerframework.checker.nullness.NullnessChecker",
"org.checkerframework.checker.units.UnitsChecker"
)
} For a list of checkers, see the Checker Framework Manual. Providing checker-specific options to the compilerYou can set the For example, to use a stub file: checkerFramework {
extraJavacArgs = [
'-Werror',
'-Astubs=/path/to/my/stub/file.astub'
]
} Configuring third-party checkersTo use a third-party typechecker (i.e. one that is not distributed with the Checker Framework),
add a dependency to the For example, to use the Glacier immutability checker: dependencies {
...
checkerFramework 'edu.cmu.cs.glacier:glacier:0.1'
} You should also use a Specifying a Checker Framework versionVersion 0.6.12 of this plugin uses Checker Framework version 3.22.1 by default. Anytime you upgrade to a newer version of this plugin, it might use a different version of the Checker Framework. You can use a Checker Framework
version that is
different than this plugin's default. For example, if you want to use Checker
Framework version 3.4.0, then you should add the following text to
dependencies {
compileOnly 'org.checkerframework:checker-qual:3.4.0'
testCompileOnly 'org.checkerframework:checker-qual:3.4.0'
checkerFramework 'org.checkerframework:checker:3.4.0'
} You can also use a locally-built version of the Checker Framework: // To use a locally-built Checker Framework, run gradle with "-PcfLocal".
if (project.hasProperty("cfLocal")) {
def cfHome = String.valueOf(System.getenv("CHECKERFRAMEWORK"))
dependencies {
compileOnly files(cfHome + "/checker/dist/checker-qual.jar")
testCompileOnly files(cfHome + "/checker/dist/checker-qual.jar")
checkerFramework files(cfHome + "/checker/dist/checker.jar")
}
} Incremental compilationBy default, the plugin assumes that all checkers are "isolating incremental annotation processors"
according to the Gradle terminology
here.
This assumption speeds up builds by enabling incremental compilation, but is unsafe: Gradle's
documentation warns that annotation processors that use internal Javac APIs may crash, because
Gradle wraps some of those APIs. The Checker Framework does use internal Javac APIs, so you
might encounter such a crash, which would appear as a checkerFramework {
incrementalize = false
} Per-Task ConfigurationYou can also use a tasks.withType(JavaCompile).configureEach {
// Don't run the checker on generated code.
if (name.equals("compileMainGeneratedDataTemplateJava")
|| name.equals("compileMainGeneratedRestJava")) {
checkerFramework {
skipCheckerFramework = true
}
}
} Currently, the only supported option is Other options
Multi-project buildsIn most projects with subprojects, the top-level project is not a Java
project. You should not apply the plugin to such a non-Java project. Instead, move
all Checker Framework configuration (the plugins {
id 'org.checkerframework' version '0.6.12' apply false
}
subprojects { subproject ->
apply plugin: 'org.checkerframework'
checkerFramework {
checkers = ['org.checkerframework.checker.index.IndexChecker']
}
dependencies {
checkerFramework 'org.checkerframework:checker:3.22.1'
implementation 'org.checkerframework:checker-qual:3.22.1'
}
} If the top-level project is a Java project that you wish to typecheck, follow these instructions but replace the 'subprojects' block with the 'allprojects' block. Alternately, apply the plugin in the Incompatibility with Error Prone 2.3.4 and earlierError Prone uses the Checker Framework's dataflow analysis library. Unfortunately, Error Prone version 2.3.4 and earlier uses an old version of the library, so you cannot use both Error Prone and the current Checker Framework (because each one depends on a different version of the library). You can resolve this by:
Here is an example of the latter approach:
Java 9+ compatibilityWhen running the plugin on a Java 9+ project that uses modules,
you may need to add annotations to the module path. First add
Then, add this line to the
Lombok compatibilityThis plugin automatically interacts with the Lombok Gradle Plugin to delombok your source code before it is passed to the Checker Framework for typechecking. This plugin does not support any other use of Lombok. By default, Lombok suppresses all warnings in the code it generates. If you
want to typecheck the code that Lombok generates, use the
Note that doing so will cause all tools (including Javac itself) to begin issuing warnings in the code that Lombok generates. Using a locally-built pluginYou can build the plugin locally rather than downloading it from Maven Central. To build the plugin from source, run If you want to use a locally-built version of the plugin, you can publish the plugin to your
local Maven repository by running
JDK 8 vs JDK 9+ implementation detailsThe plugin attempts to automatically configure the Checker Framework on both Java 8 and Java 9+ JVMs, following the best practices in the Checker Framework manual. In particular:
CreditsThis project started as a fork of an abandoned plugin built by jaredsburrows. License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论