Skip to content

Commit

Permalink
Add task to run NullAway on itself (#542)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msridhar authored Jan 6, 2022
1 parent 9228f59 commit 6c66a93
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions nullaway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ plugins {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

configurations {
nullawayJar
}

dependencies {
compileOnly deps.apt.autoValueAnnot
annotationProcessor deps.apt.autoValue
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
}
}

0 comments on commit 6c66a93

Please sign in to comment.