aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManu Sridharan <msridhar@gmail.com>2022-01-06 11:56:55 -0800
committerGitHub <noreply@github.com>2022-01-06 11:56:55 -0800
commit6c66a93cacc55f823aabbf9bf3c5155d4e63a971 (patch)
tree0c3ae9832bd3a3805f49896edfd1f196bd66918e
parent9228f59a9ae324a3aeb1227ffea7006126235424 (diff)
downloadnullaway-6c66a93cacc55f823aabbf9bf3c5155d4e63a971.tar.gz
Add task to run NullAway on itself (#542)
The task can be run as `./gradlew :nullaway:buildWithNullAway`. This turned out to be less challenging than I expected. Unfortunately, the NullAway implementation does not yet pass NullAway; we will need to address that before running this task on CI. The task only gets created when building on JDK 11+; for reasons I don't understand, the task fails to configure on JDK 8.
-rw-r--r--nullaway/build.gradle35
1 files changed, 35 insertions, 0 deletions
diff --git a/nullaway/build.gradle b/nullaway/build.gradle
index d379406..c57c7e2 100644
--- a/nullaway/build.gradle
+++ b/nullaway/build.gradle
@@ -23,6 +23,10 @@ plugins {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
+configurations {
+ nullawayJar
+}
+
dependencies {
compileOnly deps.apt.autoValueAnnot
annotationProcessor deps.apt.autoValue
@@ -53,6 +57,9 @@ dependencies {
testImplementation deps.test.springBeans
testImplementation deps.test.springContext
testImplementation deps.test.grpcCore
+
+ // This ends up being resolved to the NullAway jar under nullaway/build/libs
+ nullawayJar "com.uber.nullaway:nullaway:$VERSION_NAME"
}
javadoc {
@@ -85,3 +92,31 @@ test {
apply plugin: 'com.vanniktech.maven.publish'
+// Create a task to build NullAway with NullAway checking enabled
+// For some reason, this doesn't work on Java 8
+if (JavaVersion.current() >= JavaVersion.VERSION_11) {
+ tasks.register('buildWithNullAway', JavaCompile) {
+ // Configure compilation to run with Error Prone and NullAway
+ source = sourceSets.main.java
+ classpath = sourceSets.main.compileClasspath
+ destinationDirectory = file("$buildDir/ignoredClasses")
+ def nullawayDeps = configurations.nullawayJar.asCollection()
+ options.annotationProcessorPath = files(
+ configurations.errorprone.asCollection(),
+ sourceSets.main.annotationProcessorPath,
+ nullawayDeps)
+ options.errorprone.enabled = true
+ options.errorprone {
+ option("NullAway:AnnotatedPackages", "com.uber")
+ }
+ // Make sure the jar has already been built
+ dependsOn 'jar'
+ // Check that the NullAway jar actually exists (without this,
+ // Gradle will run the compilation even if the jar doesn't exist)
+ doFirst {
+ nullawayDeps.forEach { f ->
+ assert f.exists()
+ }
+ }
+ }
+}