-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
311 lines (281 loc) · 11.1 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
plugins {
id 'java'
id 'application' // this project includes multiple programs, not just one.
// To create a fat jar build/libs/...-all.jar, run: ./gradlew shadowJar
id 'com.gradleup.shadow' version '8.3.5'
// Code formatting; defines targets "spotlessApply" and "spotlessCheck"
// Requires JDK 11 or higher; the plugin crashes under JDK 8.
id 'com.diffplug.spotless' version '7.0.2'
// Error Prone linter
id('net.ltgt.errorprone') version '4.1.0'
// Checker Framework pluggable type-checking
id 'org.checkerframework' version '0.6.48'
// GraalVM native compilation
id 'org.graalvm.buildtools.native' version '0.10.4'
// To show Gradle dependencies, run: ./gradlew SOMETASKNAME taskTree
id "com.dorongold.task-tree" version "4.0.0"
}
repositories {
mavenLocal()
mavenCentral()
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
ext {
errorproneVersion = '2.36.0'
isJava17orHigher = JavaVersion.current() >= JavaVersion.VERSION_17
isJava21orHigher = JavaVersion.current() >= JavaVersion.VERSION_21
}
dependencies {
implementation 'com.google.googlejavaformat:google-java-format:1.25.2'
implementation 'org.plumelib:javac-parse:0.1.0'
implementation 'org.plumelib:plume-util:1.10.0'
annotationProcessor 'info.picocli:picocli-codegen:4.7.6'
implementation 'info.picocli:picocli:4.7.6'
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
// Don't use a toolchain because it uses `--release`, which is incompatible with `--add-exports`.
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
compileJava {
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
// // For Picocli native image
// options.compilerArgs += [
// "-Aproject=${project.group}/${project.name}"
// ]
}
compileTestJava {
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED'
options.compilerArgs += '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
}
test {
doFirst {
jvmArgs += [
'--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
]
}
}
test {
testLogging {
// TODO: What about "ignored"? There is no such event: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/logging/TestLogEvent.html
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
test {
testLogging {
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
task runMakefileTests(type: Exec, description: 'Run tests defined in Makefile') {
group = 'Verification'
commandLine 'make', '-C', file('src/test/resources').absolutePath
}
check.dependsOn runMakefileTests
// The "test" task runs the JUnit tests, whose failure is more informative than system tests.
runMakefileTests.mustRunAfter(test)
spotless {
format 'misc', {
// define the files to apply `misc` to
target '*.md', '.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace()
leadingTabsToSpaces(2)
endWithNewline()
}
java {
targetExclude('**/diff_match_patch.java')
googleJavaFormat()
formatAnnotations()
}
groovyGradle {
target '**/*.gradle'
greclipse() // which formatter Spotless should use to format .gradle files.
leadingTabsToSpaces(2)
trimTrailingWhitespace()
// endWithNewline() // Don't want to end empty files with a newline
}
}
application {
mainClass = 'org.plumelib.merging.Main'
}
graalvmNative {
binaries {
main {
imageName = "plumelib-merge"
mainClass = "org.plumelib.merging.Main"
buildArgs.add("-O4")
}
test {
buildArgs.add("-O0")
}
}
binaries.all {
buildArgs.add("--verbose")
// These arguments are from google-java-format's core/pom.xml.
buildArgs.add("-H:+UnlockExperimentalVMOptions")
buildArgs.add("-H:IncludeResourceBundles=com.sun.tools.javac.resources.compiler")
buildArgs.add("-H:IncludeResourceBundles=com.sun.tools.javac.resources.javac")
buildArgs.add("--no-fallback")
buildArgs.add("--initialize-at-build-time=com.sun.tools.javac.file.Locations")
buildArgs.add("-H:+ReportExceptionStackTraces")
buildArgs.add("-H:-UseContainerSupport")
buildArgs.add("-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED")
buildArgs.add("-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED")
buildArgs.add("-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED")
buildArgs.add("-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED")
buildArgs.add("-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED")
buildArgs.add("-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED")
buildArgs.add("-march=compatibility")
}
}
// Error Prone linter
dependencies {
errorprone("com.google.errorprone:error_prone_core:${errorproneVersion}")
}
tasks.withType(JavaCompile).configureEach {
// "-processing" avoids javac warning "No processor claimed any of these annotations".
options.compilerArgs << '-Xlint:all,-processing' << '-Werror'
// Only needed when debugging.
options.compilerArgs << '-g'
options.errorprone {
disable('ReferenceEquality') // Use Interning Checker instead.
// disable('StringSplitter') // Obscure case isn't likely.
disable('AnnotateFormatMethod') // Error Prone doesn't know about Checker Framework @FormatMethod
// Don't complain about external library (which is included as source because it isn't at Maven Central).
excludedPaths = '.*/diff_match_patch.java'
}
options.errorprone.enabled = isJava17orHigher
}
// Checker Framework pluggable type-checking
apply plugin: 'org.checkerframework'
checkerFramework {
checkers = [
// No need to run CalledMethodsChecker, because ResourceLeakChecker does so.
// 'org.checkerframework.checker.calledmethods.CalledMethodsChecker',
'org.checkerframework.checker.formatter.FormatterChecker',
// Passing the Index Checker should be possible; reinstate this when I have time to do so.
// 'org.checkerframework.checker.index.IndexChecker',
'org.checkerframework.checker.interning.InterningChecker',
'org.checkerframework.checker.lock.LockChecker',
'org.checkerframework.checker.nullness.NullnessChecker',
'org.checkerframework.checker.regex.RegexChecker',
'org.checkerframework.checker.resourceleak.ResourceLeakChecker',
'org.checkerframework.checker.signature.SignatureChecker',
'org.checkerframework.checker.signedness.SignednessChecker',
'org.checkerframework.common.initializedfields.InitializedFieldsChecker',
]
extraJavacArgs = [
'-Werror',
'-AcheckPurityAnnotations',
'-ArequirePrefixInWarningSuppressions',
'-AwarnRedundantAnnotations',
'-AwarnUnneededSuppressions',
'-AskipDefs=.*\\.diff_match_patch',
]
}
// To use a snapshot version of the Checker Framework.
if (false) {
// TODO: Change the above test to false when CF is released.
ext.checkerFrameworkVersion = '3.48.4'
dependencies {
compileOnly "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
testCompileOnly "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
checkerFramework "org.checkerframework:checker:${checkerFrameworkVersion}"
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'minutes'
}
}
// 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')
}
}
// Javadoc
// Turn Javadoc warnings into errors.
javadoc {
options.addStringOption('Xwerror', '-Xdoclint:all')
options.addStringOption('private', '-quiet')
options.addStringOption('source', '17')
// Buggy per https://github.com/java9-modularity/gradle-modules-plugin/issues/170
// moduleOptions {
// addExports = [
// 'jdk.compiler/com.sun.tools.javac.parser' : 'ALL-UNNAMED',
// 'jdk.compiler/com.sun.tools.javac.tree' : ' ALL-UNNAMED' ,
// 'jdk.compiler/com.sun.tools.javac.util':'ALL-UNNAMED'
// ]
// }
// Workaround until bug is fixed.
options {
addMultilineStringsOption("-add-exports").setValue([
'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
])
}
doLast {
ant.replaceregexp(match:"@import url\\('resources/fonts/dejavu.css'\\);\\s*", replace:'',
flags:'g', byline:true) {
fileset(dir: destinationDir)
}
}
}
check.dependsOn javadoc
task javadocWeb(type: Javadoc) {
description = 'Upload API documentation to website.'
source = sourceSets.main.allJava
destinationDir = file("/cse/web/research/plumelib/${project.name}/api")
classpath = project.sourceSets.main.compileClasspath
options.addStringOption('source', '11')
doLast {
ant.replaceregexp(match:"@import url\\('resources/fonts/dejavu.css'\\);\\s*", replace:'',
flags:'g', byline:true) {
fileset(dir: destinationDir)
}
}
}
configurations {
requireJavadoc
}
dependencies {
requireJavadoc 'org.plumelib:require-javadoc:1.0.9'
}
task requireJavadoc(type: JavaExec) {
description = 'Ensures that Javadoc documentation exists.'
mainClass = 'org.plumelib.javadoc.RequireJavadoc'
classpath = configurations.requireJavadoc
args 'src/main/java'
}
check.dependsOn requireJavadoc
// Emacs support
/* Make Emacs TAGS table */
task tags(type: Exec) {
description = 'Run etags to create an Emacs TAGS table'
commandLine 'bash', '-c', "find src/ \\( -name '*.java' -o -name '*.sh' \\) | sort | xargs etags"
}