-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
246 lines (219 loc) · 8.17 KB
/
build.gradle
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
buildscript {
repositories {
mavenCentral()
}
dependencies {
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.25.0'
}
}
}
plugins {
id "java"
id "maven-publish"
// https://github.com/tbroyer/gradle-errorprone-plugin
id 'net.ltgt.errorprone' version '4.0.1'
}
repositories {
mavenCentral()
mavenLocal()
}
configurations {
javacJar
// for putting Error Prone javac in bootclasspath for running tests
errorproneJavac
// local dependency
localDeps
}
ext.versions = [
checkerFramework: "3.42.0-eisop4",
errorproneJavacVersion: "9+181-r4173-1",
errorproneCoreVersion: "2.31.0",
]
java {
sourceCompatibility = JavaVersion.VERSION_1_8
}
def checkerframework_local = false // Set this variable to [true] while using local version of checker framework.
def CHECKERFRAMEWORK = System.getenv("CHECKERFRAMEWORK")
ext {
isJava11plus = JavaVersion.current() >= JavaVersion.VERSION_11
}
dependencies {
// This dependency is found on compile classpath of this component and consumers.
// TODO: clean up implementation/localDeps duplication.
if (checkerframework_local) {
if (CHECKERFRAMEWORK == null) {
CHECKERFRAMEWORK = "../checker-framework/"
}
implementation files("${CHECKERFRAMEWORK}/checker/dist/checker-qual.jar")
implementation files("${CHECKERFRAMEWORK}/checker/dist/checker.jar")
localDeps files("${CHECKERFRAMEWORK}/checker/dist/checker.jar")
} else {
implementation "io.github.eisop:checker:${versions.checkerFramework}"
localDeps "io.github.eisop:checker:${versions.checkerFramework}"
implementation "io.github.eisop:checker-qual:${versions.checkerFramework}"
localDeps "io.github.eisop:checker-qual:${versions.checkerFramework}"
implementation "io.github.eisop:checker-util:${versions.checkerFramework}"
localDeps "io.github.eisop:checker-util:${versions.checkerFramework}"
}
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
javacJar group: 'com.google.errorprone', name: 'javac', version: "${versions.errorproneJavacVersion}"
}
errorprone "com.google.errorprone:error_prone_core:${versions.errorproneCoreVersion}"
errorproneJavac "com.google.errorprone:javac:${versions.errorproneJavacVersion}"
// Testing
testImplementation "junit:junit:4.13.2"
testImplementation "io.github.eisop:framework-test:${versions.checkerFramework}"
testImplementation "org.apache.httpcomponents:httpclient:4.5.14"
testImplementation "org.springframework:spring-web:5.3.18"
errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"
}
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
resources {
srcDirs = ["src/main/java"]
exclude "**/*.java"
}
}
test {
java {
srcDirs = ["src/test/java"]
}
}
}
if (isJava11plus) {
apply plugin: 'com.diffplug.spotless'
spotless {
java {
target "src/**/*.java", "tests/**/*.java"
googleJavaFormat().aosp()
formatAnnotations()
removeUnusedImports()
importOrder('com', 'jdk', 'lib', 'lombok', 'org', 'java', 'javax')
}
format "misc", {
target "**/.gitignore"
trimTrailingWhitespace()
indentWithTabs()
endWithNewline()
}
groovyGradle {
target '**/*.gradle'
greclipse() // which formatter Spotless should use to format .gradle files.
indentWithSpaces(4)
trimTrailingWhitespace()
// endWithNewline() // Don't want to end empty files with a newline
}
}
}
// Run `./gradlew publishToMavenLocal` to publish your checker to your local Maven repository.
publishing {
publications {
maven(MavenPublication) {
groupId = "io.github.eisop"
artifactId = "network-request-checker"
version = "0.1-SNAPSHOT"
from components.java
if (checkerframework_local) {
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode("groupId", "io.github.eisop")
dependencyNode.appendNode("artifactId", "checker")
dependencyNode.appendNode("version", "${versions.checkerFramework}")
dependencyNode.appendNode("systemPath", projectDir.toString() + "$buildDir/libs/checker.jar")
}
}
}
}
}
test {
inputs.files("tests/networkrequest")
if (!JavaVersion.current().java9Compatible) {
jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}"
}
}
test.dependsOn(":assemble")
assemble.dependsOn(":clean")
afterEvaluate {
// Configure JUnit tests
tasks.withType(Test) {
testLogging {
// Always run the tests
outputs.upToDateWhen { false }
// The following prints out each time a test is passed.
events "passed", "skipped", "failed", "standardOut", "standardError"
// Show the found unexpected diagnostics and expected diagnostics not found.
exceptionFormat "full"
showExceptions true
showCauses true
showStackTraces true
showStandardStreams true
}
// After each test, print a summary.
afterSuite { desc, result ->
if (desc.getClassName() != null) {
long mils = result.getEndTime() - result.getStartTime()
double seconds = mils / 1000.0
println()
println "Testsuite: ${desc.getClassName()}\n" +
"Tests run: ${result.testCount}, " +
"Failures: ${result.failedTestCount}, " +
"Skipped: ${result.skippedTestCount}, " +
"Time elapsed: ${seconds} sec"
}
}
}
// Code adapted from checker-framework:
// https://github.com/eisop/checker-framework/blob/567084f11278273b33289d138d9d2a1b513d3c35/build.gradle#L226
tasks.withType(JavaCompile) { compilationTask ->
sourceCompatibility = 8
targetCompatibility = 8
options.failOnError = true
options.deprecation = true
options.compilerArgs += [
'-g',
'-Werror',
"-Xlint:all",
]
options.encoding = 'UTF-8'
options.fork = true
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
options.forkOptions.jvmArgs += [
"-Xbootclasspath/p:${configurations.javacJar.asPath}".toString()
]
options.errorprone.enabled = false
} else {
options.errorprone.enabled = true
options.forkOptions.jvmArgs += [
'--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.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-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
]
}
}
}
clean.doFirst {
delete "${rootDir}/tests/build/"
}
test.doLast {
delete "${rootDir}/tests/build/",
fileTree("tests/") { include "**/*.class" }
}
task copyDependencies(type: Copy) {
from configurations.localDeps
into "$buildDir/libs"
}
task printLocalCheckerFrameworkPath() {
println CHECKERFRAMEWORK
}