forked from plume-lib/options
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
238 lines (209 loc) · 7.69 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
buildscript {
dependencies {
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
// Code formatting; defines targets "spotlessApply" and "spotlessCheck".
// https://github.com/diffplug/spotless/tags ; see tags starting "gradle/"
// Only works on JDK 11+.
classpath 'com.diffplug.spotless:spotless-plugin-gradle:7.0.1'
}
}
}
plugins {
id 'java-library'
// To create a fat jar build/libs/...-all.jar, run: ./gradlew shadowJar
id 'com.gradleup.shadow' version '8.3.5'
// Error Prone linter
id 'net.ltgt.errorprone' version '4.1.0'
// Checker Framework pluggable type-checking
id 'org.checkerframework' version '0.6.48' apply false
}
repositories {
mavenCentral()
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
ext {
errorproneVersion = '2.36.0'
isJava11orHigher = JavaVersion.current() >= JavaVersion.VERSION_11
isJava17orHigher = JavaVersion.current() >= JavaVersion.VERSION_17
isJava21orHigher = JavaVersion.current() >= JavaVersion.VERSION_21
}
dependencies {
implementation 'io.github.classgraph:classgraph:4.8.179'
implementation 'org.apache.commons:commons-lang3:3.17.0'
implementation 'org.apache.commons:commons-text:1.13.0'
implementation 'org.plumelib:reflection-util:1.1.4'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.4'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
// To upload to Maven Central, see instructions in the file.
apply from: "${buildscript.sourceFile.parent}/gradle/mavencentral.gradle"
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
// Work around https://github.com/johnrengelman/shadow/issues/324
configurations {
toolsJar // tools.jar contains the Javadoc tool
}
configurations.compileClasspath.extendsFrom configurations.toolsJar
test {
useJUnitPlatform {
includeEngines 'junit-jupiter'
excludeEngines 'junit-vintage'
}
}
if (isJava11orHigher) {
apply plugin: 'com.diffplug.spotless'
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('**/WeakIdentityHashMap.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
}
}
}
// Error Prone linter
dependencies {
compileOnly "com.google.errorprone:error_prone_annotations:${errorproneVersion}"
errorprone("com.google.errorprone:error_prone_core:${errorproneVersion}")
}
tasks.withType(JavaCompile).configureEach {
// "-processing" avoids javac warning "No processor claimed any of these annotations".
// "-classfile" is because of classgraph and https://bugs.openjdk.java.net/browse/JDK-8190452
options.compilerArgs << '-Xlint:all,-processing,-classfile' << '-Werror'
options.errorprone {
disable('ExtendsObject') // Incorrect when using the Checker Framework
disable('ReferenceEquality') // Use Interning Checker instead.
disable('StringSplitter') // Obscure case isn't likely.
disable('AnnotateFormatMethod') // Error Prone doesn't know about Checker Framework @FormatMethod
disable('UseCorrectAssertInTests') // https://github.com/typetools/checker-framework/issues/3345
}
options.errorprone.enabled = isJava17orHigher
}
// Checker Framework pluggable type-checking
apply plugin: 'org.checkerframework'
if (true) {
// Use the released version of the EISOP Checker Framework.
ext.checkerFrameworkVersion = '3.42.0-eisop5'
} else {
// To use a snapshot version of the EISOP Checker Framework.
// TODO: Change the above test to false to use a snapshot.
ext.checkerFrameworkVersion = '3.42.0-eisop5'
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'minutes'
}
}
dependencies {
compileOnly "io.github.eisop:checker-qual:${checkerFrameworkVersion}"
testCompileOnly "io.github.eisop:checker-qual:${checkerFrameworkVersion}"
checkerFramework "io.github.eisop:checker-qual:${checkerFrameworkVersion}"
checkerFramework "io.github.eisop:checker:${checkerFrameworkVersion}"
}
// 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')
}
}
checkerFramework {
checkers = [
// No need to run CalledMethodsChecker, because ResourceLeakChecker does so.
// 'org.checkerframework.checker.calledmethods.CalledMethodsChecker',
'org.checkerframework.checker.formatter.FormatterChecker',
'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',
'-AnoJreVersionCheck',
'-Aversion',
]
}
// Javadoc
// Turn Javadoc warnings into errors.
javadoc {
options.addStringOption('Xwerror')
options.addStringOption('Xdoclint:all', '-quiet')
options.addStringOption('private', '-quiet')
options.addStringOption('source', '11')
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)
}
// Set permissions
project.exec {
commandLine('chgrp', '-R', 'plse_www', "/cse/web/research/plumelib/${project.name}/api")
}
project.exec {
commandLine('chmod', '-R', 'g+w', "/cse/web/research/plumelib/${project.name}/api")
}
}
}
configurations {
requireJavadoc
}
dependencies {
requireJavadoc 'org.plumelib:require-javadoc:1.0.9'
}
task requireJavadoc(type: JavaExec) {
// Gradle resolves requireJavadoc's Option dependency to the jar built by this project,
// so declare an explicit dependency on jar.
dependsOn jar
group = 'Documentation'
description = 'Ensures that Javadoc documentation exists.'
mainClass = 'org.plumelib.javadoc.RequireJavadoc'
classpath = configurations.requireJavadoc
args 'src/main/java'
}
check.dependsOn requireJavadoc
javadocWeb.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' | sort | xargs etags"
}