1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
* Copyright (C) 2017. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import net.ltgt.gradle.errorprone.CheckSeverity
plugins {
id 'java-library'
id 'nullaway.java-test-conventions'
}
configurations {
nullawayJar
}
dependencies {
compileOnly project(":annotations")
compileOnly deps.apt.autoValueAnnot
annotationProcessor deps.apt.autoValue
compileOnly deps.apt.autoServiceAnnot
annotationProcessor deps.apt.autoService
compileOnly deps.build.jsr305Annotations
compileOnly deps.test.jetbrainsAnnotations
compileOnly deps.apt.javaxInject
compileOnly deps.build.errorProneCheckApi
implementation deps.build.checkerDataflow
implementation deps.build.guava
testImplementation project(":annotations")
testImplementation deps.test.junit4
testImplementation(deps.build.errorProneTestHelpers) {
exclude group: "junit", module: "junit"
}
testImplementation deps.test.jetbrainsAnnotations
testImplementation deps.test.junit5Jupiter
testImplementation deps.test.cfQual
testImplementation deps.test.cfCompatQual
testImplementation deps.build.jspecify
testImplementation project(":test-java-lib")
testImplementation deps.apt.jakartaInject
testImplementation deps.apt.javaxInject
testImplementation deps.test.rxjava2
testImplementation deps.test.commonsLang
testImplementation deps.test.commonsLang3
testImplementation project(":test-library-models")
testImplementation deps.test.lombok
testImplementation deps.test.springBeans
testImplementation deps.test.springContext
testImplementation deps.test.grpcCore
testImplementation project(":test-java-lib-lombok")
testImplementation deps.test.mockito
testImplementation deps.test.javaxAnnotationApi
testImplementation deps.test.assertJ
}
javadoc {
failOnError = false
}
apply plugin: 'com.vanniktech.maven.publish'
// These --add-exports arguments are required when targeting JDK 11+ since Error Prone and NullAway access a bunch of
// JDK-internal APIs that are not exposed otherwise. Since we currently target JDK 8, we do not need to pass the
// arguments, as encapsulation of JDK internals is not enforced on JDK 8. In fact, the arguments cause a compiler error
// when targeting JDK 8. Leaving commented so we can easily add them back once we target JDK 11.
// tasks.withType(JavaCompile).configureEach {
// options.compilerArgs += [
// "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
// "--add-exports=jdk.compiler/com.sun.source.tree=ALL-UNNAMED",
// ]
// }
// Create a task to test on JDK 8
def jdk8Test = tasks.register("testJdk8", Test) {
onlyIf {
// Only if we are using a version of Error Prone compatible with JDK 8
deps.versions.errorProneApi == "2.10.0"
}
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(8)
}
description = "Runs the test suite on JDK 8"
group = LifecycleBasePlugin.VERIFICATION_GROUP
// Copy inputs from normal Test task.
def testTask = tasks.getByName("test")
classpath = testTask.classpath
testClassesDirs = testTask.testClassesDirs
jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}"
filter {
// JDK 8 does not support diamonds on anonymous classes
excludeTestsMatching "com.uber.nullaway.NullAwayJSpecifyGenericsTests.overrideDiamondAnonymousClass"
// tests cannot run on JDK 8 since Mockito version no longer supports it
excludeTestsMatching "com.uber.nullaway.NullAwaySerializationTest.initializationError"
excludeTestsMatching "com.uber.nullaway.handlers.contract.ContractUtilsTest.getEmptyAntecedent"
}
}
tasks.named('check').configure {
dependsOn(jdk8Test)
}
tasks.named('testJdk21', Test).configure {
filter {
// JSpecify Generics tests do not yet pass on JDK 21
// See https://github.com/uber/NullAway/issues/827
excludeTestsMatching "com.uber.nullaway.NullAwayJSpecifyGenericsTests"
}
}
// Create a task to build NullAway with NullAway checking enabled
tasks.register('buildWithNullAway', JavaCompile) {
onlyIf {
// We only do NullAway checks when compiling against the latest
// version of Error Prone (as nullability annotations on the APIs
// can change between versions)
deps.versions.errorProneApi == deps.versions.errorProneLatest
}
// Configure compilation to run with Error Prone and NullAway
source = sourceSets.main.java
classpath = sourceSets.main.compileClasspath
destinationDirectory = file("$buildDir/ignoredClasses")
options.annotationProcessorPath = files(
configurations.errorprone.asCollection(),
sourceSets.main.annotationProcessorPath,
// This refers to the NullAway jar built from the current source
jar.archiveFile.get(),
sourceSets.main.compileClasspath)
options.errorprone.enabled = true
options.errorprone {
option("NullAway:AnnotatedPackages", "com.uber,org.checkerframework.nullaway")
option("NullAway:CastToNonNullMethod", "com.uber.nullaway.NullabilityUtil.castToNonNull")
option("NullAway:CheckOptionalEmptiness")
option("NullAway:AcknowledgeRestrictiveAnnotations")
option("NullAway:CheckContracts")
option("NullAway:JSpecifyMode")
}
// 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 {
assert jar.archiveFile.get().getAsFile().exists()
}
}
project.tasks.named('check').configure {
dependsOn 'buildWithNullAway'
}
|