This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
/
build.gradle
680 lines (621 loc) · 19.7 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
}
}
plugins {
id 'checkstyle'
id 'eclipse'
id 'signing'
id 'java'
id 'java-library'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '4.0.3'
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
}
apply from: "gradle/java-compatibility.gradle"
apply from: "gradle/publication.gradle"
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
sourceSets {
main {
java {
srcDir file('generated/main/java')
}
}
}
dependencies {
implementation googleJavaFormat
implementation guava
compileOnly autoService
compileOnly files(jvms["1.8"].toolsJar)
annotationProcessor autoService
testImplementation guavaTestlib
testImplementation gwtUser
testImplementation hamcrest
testImplementation jackson('annotations')
testImplementation jackson('core')
testImplementation jackson('databind')
testImplementation jackson('datatype-guava')
testImplementation jackson('datatype-jdk8')
testImplementation jackson('dataformat-xml')
testImplementation javassist
testImplementation jsr305
testImplementation junit
testImplementation mockito
testImplementation reflections
testImplementation truth
}
//// Jackson /////////////////////////////////////////////////////
String jackson(String pkg) {
String namespace
if (pkg.startsWith('datatype-')) {
namespace = 'datatype'
} else if (pkg.startsWith('dataformat-')) {
namespace = 'dataformat'
} else {
namespace = 'core'
}
return String.format('com.fasterxml.jackson.%s:jackson-%s:%s',
namespace, pkg, jacksonVersion)
}
class JacksonAlignmentRule implements ComponentMetadataRule {
void execute(ComponentMetadataContext ctx) {
ctx.details.with {
if (id.group.startsWith("com.fasterxml.jackson")) {
belongsTo("com.fasterxml.jackson:jackson-platform:${id.version}")
}
}
}
}
dependencies {
components.all(JacksonAlignmentRule)
}
//// Testing /////////////////////////////////////////////////////
test {
maxHeapSize = "1024m"
testLogging {
exceptionFormat = 'full'
}
maxParallelForks = Integer.min(Runtime.runtime.availableProcessors(), 2)
}
check.dependsOn javadoc
tasks.withType(Javadoc) {
options.addStringOption 'Xdoclint:-missing', '-quiet'
}
//// Checkstyle //////////////////////////////////////////////////
checkstyle {
toolVersion = "6.19"
configProperties.configDir = "$rootDir/config/checkstyle"
}
tasks.withType(Checkstyle).each { checkstyleTask ->
checkstyleTask.doLast {
reports.all { report ->
def outputFile = report.destination
if (outputFile.exists() && outputFile.text.contains("<error ")) {
throw new GradleException("There were checkstyle warnings! See $outputFile")
}
}
}
}
eclipse.project {
natures 'net.sf.eclipsecs.core.CheckstyleNature'
buildCommand 'net.sf.eclipsecs.core.CheckstyleBuilder'
}
//// Shadow JAR //////////////////////////////////////////////////
jar {
classifier = 'only'
}
shadowJar {
classifier = null
['com.google', 'org.apache', 'org.openjdk', 'org.osgi'].each {
relocate it, "org.inferred.freebuilder.shaded.$it"
}
include '*.jar'
// Include critical META-INF files
include 'META-INF/MANIFEST.MF'
include 'META-INF/services/javax.annotation.processing.Processor'
// Include FreeBuilder
include 'org/inferred/freebuilder/**'
// Include Guava
include 'com/google/common/**'
// Include Google's Java formatter
include 'com/google/googlejavaformat/**'
include 'org/openjdk/**'
exclude 'org/openjdk/tools/javadoc/**'
}
tasks.shadowJar.shouldRunAfter tasks.test
import java.util.zip.ZipFile
import java.util.zip.ZipException
tasks.register("shadowTest") {
description 'Verifies freebuilder.jar is shaded correctly.'
group = 'Verification'
check.dependsOn it
dependsOn shadowJar
def expected = new File("$projectDir/jar-footprint.txt")
def report = new File("$reportsDir/shadowJarFootprint.txt")
inputs.files shadowJar.outputs
inputs.file expected
outputs.file report
doFirst {
def jar = shadowJar.outputs.files[0]
def zip = new ZipFile(jar)
def folders = new TreeSet<String>(zip.entries().collect {
it.toString().replaceAll('([^/]*(/[^/]*){0,3}).*', '$1')
})
def expectedFolders = new TreeSet<String>(expected.readLines())
report.parentFile.mkdirs()
if (expectedFolders != folders) {
def message = new StringBuilder('shadow.jar incorrect')
def missing = expectedFolders - folders
if (!missing.isEmpty()) {
message.append('\nThe following are missing:')
missing.forEach { message.append('\n - ').append(it) }
}
def extra = folders - expectedFolders
if (!extra.isEmpty()) {
message.append('\nThe following should not be present:')
extra.forEach { message.append('\n - ').append(it) }
}
report.write message.toString()
throw new GradleException(message.toString())
}
report.write 'shadow.jar correct'
}
}
//// Vanilla integration tests ///////////////////////////////////
configurations {
vanillaCompile
vanillaTestCompile.extendsFrom vanillaCompile
}
dependencies {
vanillaCompile guava
vanillaCompile gwtUser
vanillaCompile jackson('core')
vanillaCompile jackson('databind')
vanillaTestCompile junit
}
tasks.register("vanillaTest") {
description 'Runs the vanilla integration tests.'
group = 'Verification'
check.dependsOn it
}
(8..11).each { jdk ->
def sourceSet = sourceSets.create("vanilla${jdk}") {
java {
srcDir file('src/it/vanilla/src/main/java')
compileClasspath += shadowJar.outputs.files
annotationProcessorPath += shadowJar.outputs.files
}
}
def testSourceSet = sourceSets.create("vanilla${jdk}Test") {
java {
srcDir file('src/it/vanilla/src/test/java')
compileClasspath += sourceSet.output
runtimeClasspath += sourceSet.output
}
}
tasks.getByName("compileVanilla${jdk}Java") {
sourceCompatibility = jdk
targetCompatibility = jdk
}
tasks.getByName("compileVanilla${jdk}TestJava") {
sourceCompatibility = jdk
targetCompatibility = jdk
}
def compile = configurations["vanilla${jdk}Compile"]
def runtime = configurations["vanilla${jdk}Runtime"]
def testCompile = configurations["vanilla${jdk}TestCompile"]
def testRuntime = configurations["vanilla${jdk}TestRuntime"]
compile.extendsFrom configurations['vanillaCompile']
testCompile.extendsFrom configurations['vanillaTestCompile']
testCompile.extendsFrom compile
testRuntime.extendsFrom runtime
def test = tasks.register("vanilla${jdk}Test", Test) {
vanillaTest.dependsOn it
testClassesDirs = sourceSets["vanilla${jdk}Test"].output.classesDirs
classpath = sourceSets["vanilla${jdk}Test"].runtimeClasspath
executable jdk
reports {
html {
destination file("$reportsDir/vanilla${jdk}")
}
}
}
}
//// GWT integration tests ///////////////////////////////////////
configurations {
gwtCompile
gwtCompileOnly
gwtTestCompile.extendsFrom gwtCompile
}
dependencies {
gwtCompile 'com.google.guava:guava-gwt:20.0'
gwtCompile gwt('codeserver')
gwtCompileOnly gwt('dev')
gwtCompile gwt('elemental')
gwtCompile gwt('servlet')
gwtCompileOnly gwt('user')
gwtTestCompile junit
}
String gwt(String pkg) {
return 'com.google.gwt:gwt-' + pkg + ':2.8.0'
}
sourceSets.create('gwt') {
java {
srcDir file('src/it/gwt/src/main/java')
compileClasspath += shadowJar.outputs.files
annotationProcessorPath += shadowJar.outputs.files
}
resources {
srcDir file('src/it/gwt/src/main/resources')
}
}
sourceSets.create('gwtTest') {
java {
srcDir file('src/it/gwt/src/test/java')
compileClasspath += sourceSets.gwt.output
runtimeClasspath += sourceSets.gwt.output
}
resources {
srcDir file('src/it/gwt/src/test/resources')
}
runtimeClasspath += files(sourceSets.gwt.allJava.srcDirs)
runtimeClasspath += files(sourceSets.gwtTest.allJava.srcDirs)
}
tasks.compileGwtJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.compileGwtTestJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
import de.richsource.gradle.plugins.gwt.GwtCompile
import de.richsource.gradle.plugins.gwt.LogLevel
tasks.register("compileGwtToJs", GwtCompile) {
def gwtDir = new File(buildDir, 'gwt')
war = new File(gwtDir, 'out')
extra = new File(gwtDir, 'extra')
workDir = new File(gwtDir, 'work')
gen = new File(gwtDir, 'gen')
cacheDir = new File(gwtDir, 'cache')
logLevel = LogLevel.INFO
group = 'GWT'
modules = ['org.inferred.freebuilder.TestServer']
src = files(sourceSets['gwt'].allJava.srcDirs,
sourceSets['gwt'].output.generatedSourcesDirs,
sourceSets['gwt'].output.resourcesDir,
sourceSets['gwtTest'].allJava.srcDirs,
sourceSets['gwt'].output.generatedSourcesDirs,
sourceSets['gwtTest'].output.resourcesDir)
classpath = (sourceSets['gwt'].compileClasspath +
sourceSets['gwtTest'].compileClasspath)
sourceLevel = '1.8'
incremental = false
strict = true
dependsOn gwtClasses, gwtTestClasses
}
tasks.register("gwtTest", Test) {
description 'Runs the GWT integration tests.'
group = 'Verification'
check.dependsOn it
dependsOn compileGwtToJs
testClassesDirs = sourceSets.gwtTest.output.classesDirs
classpath = sourceSets.gwtTest.runtimeClasspath
include 'org/inferred/freebuilder/GwtTests'
reports {
html {
destination file("$reportsDir/gwt")
}
}
testLogging.showStandardStreams = true
def gwtArgs = new StringBuilder()
for (def key in ["war", "extra", "workDir", "gen", "logLevel"]) {
def value = compileGwtToJs[key]
gwtArgs.append(" -$key $value")
}
systemProperty("gwt.args", gwtArgs.toString())
systemProperty("gwt.persistentunitcachedir", compileGwtToJs.cacheDir)
}
//// No-guava integration tests //////////////////////////////////
configurations {
noGuavaCompile
noGuavaTestCompile.extendsFrom noGuavaCompile
}
dependencies {
noGuavaCompile gwtUser
noGuavaTestCompile junit
}
tasks.register("noGuavaTest") {
description 'Runs the no-guava integration tests.'
group = 'Verification'
check.dependsOn it
}
(8..8).each { jdk ->
def sourceSet = sourceSets.create("noGuava${jdk}") {
java {
srcDir file('src/it/no-guava/src/main/java')
compileClasspath += shadowJar.outputs.files
annotationProcessorPath += shadowJar.outputs.files
}
}
def testSourceSet = sourceSets.create("noGuava${jdk}Test") {
java {
srcDir file('src/it/no-guava/src/test/java')
compileClasspath += sourceSet.output
runtimeClasspath += sourceSet.output
}
}
tasks.getByName("compileNoGuava${jdk}Java") {
sourceCompatibility = "1.$jdk"
targetCompatibility = "1.$jdk"
}
tasks.getByName("compileNoGuava${jdk}TestJava") {
sourceCompatibility = "1.$jdk"
targetCompatibility = "1.$jdk"
}
def compile = configurations["noGuava${jdk}Compile"]
def runtime = configurations["noGuava${jdk}Runtime"]
def testCompile = configurations["noGuava${jdk}TestCompile"]
def testRuntime = configurations["noGuava${jdk}TestRuntime"]
compile.extendsFrom configurations['noGuavaCompile']
testCompile.extendsFrom configurations['noGuavaTestCompile']
testCompile.extendsFrom compile
testRuntime.extendsFrom runtime
def test = tasks.register("noGuava${jdk}Test", Test) {
noGuavaTest.dependsOn it
testClassesDirs = sourceSets["noGuava${jdk}Test"].output.classesDirs
classpath = sourceSets["noGuava${jdk}Test"].runtimeClasspath
reports {
html {
destination file("$reportsDir/noGuava${jdk}")
}
}
}
}
//// No-guava-j8 integration tests ///////////////////////////////
configurations {
noGuavaJ8Compile
noGuavaJ8TestCompile.extendsFrom noGuavaJ8Compile
}
dependencies {
noGuavaJ8TestCompile junit
}
sourceSets.create("noGuavaJ8") {
java {
srcDir file('src/it/no-guava-j8/src/main/java')
compileClasspath += shadowJar.outputs.files
annotationProcessorPath += shadowJar.outputs.files
}
}
sourceSets.create("noGuavaJ8Test") {
java {
srcDir file('src/it/no-guava-j8/src/test/java')
compileClasspath += sourceSets.noGuavaJ8.output
runtimeClasspath += sourceSets.noGuavaJ8.output
}
}
tasks.compileNoGuavaJ8Java {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.compileNoGuavaJ8TestJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.register("noGuavaJ8Test", Test) {
description 'Runs the no-guava-j8 integration tests.'
group = 'Verification'
check.dependsOn it
testClassesDirs = sourceSets.noGuavaJ8Test.output.classesDirs
classpath = sourceSets.noGuavaJ8Test.runtimeClasspath
reports {
html {
destination file("$reportsDir/noGuavaJ8")
}
}
}
//// Lambda integration tests ////////////////////////////////////
configurations {
lambdaCompile
lambdaTestCompile.extendsFrom lambdaCompile
}
dependencies {
lambdaCompile guava
lambdaCompile gwtUser
lambdaTestCompile junit
}
sourceSets.create('lambda') {
java {
srcDir file('src/it/lambda/src/main/java')
compileClasspath += shadowJar.outputs.files
annotationProcessorPath += shadowJar.outputs.files
}
}
sourceSets.create('lambdaTest') {
java {
srcDir file('src/it/lambda/src/test/java')
compileClasspath += sourceSets.lambda.output
runtimeClasspath += sourceSets.lambda.output
}
}
tasks.compileLambdaJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.compileLambdaTestJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.register("lambdaTest", Test) {
description 'Runs the lambda integration tests.'
group = 'Verification'
check.dependsOn it
testClassesDirs = sourceSets["lambdaTest"].output.classesDirs
classpath = sourceSets["lambdaTest"].runtimeClasspath
reports {
html {
destination file("$reportsDir/lambda")
}
}
}
//// Publication /////////////////////////////////////////////////
group = 'org.inferred'
archivesBaseName = 'freebuilder'
if (System.env.GITHUB_REF_TYPE == 'tag') {
version = System.env.GITHUB_REF_NAME.replaceAll('^v','')
} else {
version = 'UNKNOWN-SNAPSHOT'
}
pom {
project {
groupId = 'org.inferred'
artifactId = 'freebuilder'
name = 'FreeBuilder'
description = 'Automatic generation of the Builder pattern for Java 1.8+'
url = 'http://freebuilder.inferred.org/'
license = apache2
}
scm {
github 'inferred/freebuilder'
}
developers {
developer {
id = 'alicederyn'
name = 'Alice Purcell'
email = 'alicederyn@gmail.com'
timezone = 'Europe/London'
}
}
}
//// Eclipse /////////////////////////////////////////////////////
eclipse.classpath {
// src/main/java is compiled in a separate project
// This allows us to compile it with an older JVM than the tests
file.withXml { xml ->
node = xml.asNode()
node.findAll { it.@kind == 'src' &&
( it.@path.contains('/test/') ||
it.@path.contains('/it/')) }
.each { src -> node.remove(src) }
}
// Don't include test dependencies in the classpath
plusConfigurations.clear()
plusConfigurations += [ configurations.compileClasspath ]
}
// Exclude everything in src except src/main
eclipse.project.file.withXml {
if (asNode().find { it.name() == 'filteredResources' } == null) {
asNode().append(new XmlParser().parseText("""
<filteredResources>
<filter>
<id>""" + System.currentTimeMillis() + """</id>
<name>src</name>
<type>9</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-main</arguments>
</matcher>
</filter>
</filteredResources>
"""))
}
}
import org.gradle.plugins.ide.eclipse.model.EclipseModel
import org.gradle.plugins.ide.eclipse.model.EclipseClasspath
import org.gradle.plugins.ide.eclipse.model.EclipseJdt
import org.gradle.api.internal.PropertiesTransformer
import org.gradle.plugins.ide.api.PropertiesFileContentMerger
def eclipseTestModel = extensions.create("eclipseTest", EclipseModel.class, project)
eclipseTestModel.jdt = objects.newInstance(EclipseJdt, new PropertiesFileContentMerger(new PropertiesTransformer()))
eclipseTestModel.classpath = objects.newInstance(EclipseClasspath, project)
eclipseTest {
project {
buildCommand 'org.eclipse.jdt.core.javabuilder'
natures "org.eclipse.jdt.core.javanature"
natures 'net.sf.eclipsecs.core.CheckstyleNature'
buildCommand 'net.sf.eclipsecs.core.CheckstyleBuilder'
linkedResource name: 'src', type:'2', location: 'PARENT-1-PROJECT_LOC/src/test/java'
}
jdt {
conventionMapping.map('sourceCompatibility') { JavaVersion.toVersion(compileTestJava.sourceCompatibility) }
conventionMapping.map('targetCompatibility') { JavaVersion.toVersion(compileTestJava.targetCompatibility) }
conventionMapping.map('javaRuntimeName') { 'JavaSE-' + jdt.targetCompatibility }
}
}
eclipseTest.project.name = project.name + '-test'
import org.gradle.plugins.ide.eclipse.GenerateEclipseProject
task eclipseTestProject(type: GenerateEclipseProject, constructorArgs: [eclipseTest.project]) {
description = 'Generates the Eclipse test project file.'
inputFile = project.file('.test/.project')
outputFile = inputFile
tasks.eclipse.dependsOn it
}
import org.gradle.plugins.ide.eclipse.GenerateEclipseJdt
task eclipseTestJdt(type: GenerateEclipseJdt, constructorArgs: [eclipseTest.jdt]) {
description = 'Generates the Eclipse test JDT settings file.'
inputFile = project.file('.test/.settings/org.eclipse.jdt.core.prefs')
outputFile = inputFile
tasks.eclipse.dependsOn it
}
import org.gradle.plugins.ide.eclipse.GenerateEclipseClasspath
import org.gradle.internal.xml.XmlTransformer
import org.gradle.plugins.ide.api.XmlFileContentMerger
import org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry
task eclipseTestClasspath(type: GenerateEclipseClasspath, constructorArgs: [eclipseTest.classpath]) {
description = 'Generates the Eclipse test classpath file.'
inputFile = project.file('.test/.classpath')
outputFile = inputFile
classpath.file = new XmlFileContentMerger((XmlTransformer) getProperty('xmlTransformer'))
classpath.sourceSets = []
project.afterEvaluate {
Set<String> containers = new LinkedHashSet<>()
containers.add(
'org.eclipse.jdt.launching.JRE_CONTAINER/'
+ 'org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/'
+ eclipseTest.jdt.javaRuntimeName + '/')
containers.addAll(classpath.containers)
classpath.containers = containers
}
classpath.plusConfigurations += [
configurations.testCompileClasspath,
configurations.testRuntimeClasspath
]
classpath.file.whenMerged {
entries.each { entry ->
if (entry instanceof AbstractClasspathEntry) {
// Remove test attribute, as this causes Eclipse to complain about missing class files
// https://github.com/gradle/gradle/blob/v5.6.0/subprojects/ide/src/main/java/org/gradle/plugins/ide/eclipse/model/internal/EclipseDependenciesCreator.java#L211
entry.entryAttributes.remove("test")
}
}
}
classpath.defaultOutputDir = project.file('.test/bin')
dependsOn sourceSets.main.output.dirs
dependsOn sourceSets.test.output.dirs
tasks.eclipse.dependsOn it
}
eclipseTest.classpath.file.withXml { xml ->
xml.asNode().appendNode('classpathentry', [
combineaccessrules: 'false',
kind: 'src',
path: '/' + project.name
])
if (xml.asNode().find { it.@kind == 'src' && it.@path == 'src' } == null) {
xml.asNode().appendNode('classpathentry', [
kind: 'src',
path: 'src'
])
}
}