-
Notifications
You must be signed in to change notification settings - Fork 470
/
build.gradle
456 lines (405 loc) · 15.4 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
import java.time.Duration
import static org.spockframework.gradle.AsciiDocLinkVerifier.verifyAnchorlessCrossDocumentLinks
import static org.spockframework.gradle.AsciiDocLinkVerifier.verifyLinksAndAnchors
plugins {
id "org.spockframework.base" apply false
id "base"
id "org.asciidoctor.jvm.convert"
id "jacoco"
id "net.nemerosa.versioning"
id "io.github.gradle-nexus.publish-plugin"
id "com.github.ben-manes.versions"
id "io.spring.nohttp"
}
description = "Spock Framework"
ext {
baseVersion = "2.4"
snapshotVersion = true
milestone = 0
javaVersions = [8, 11, 17, 21] // ensure that latest version is actually build on GH actions and added to gradle.properties, otherwise no docs get published
javaVersion = (System.getProperty("javaVersion") ?: 8) as int
variants = [2.5, 3.0, 4.0]
variant = System.getProperty("variant") as BigDecimal ?: variants.first()
develocity.buildScan.tag "groovy-$variant"
if (variant == 2.5) {
groovyGroup = "org.codehaus.groovy"
groovyVersion = libs.versions.groovy2.get()
minGroovyVersion = "2.5.0"
maxGroovyVersion = "2.9.99"
if (javaVersion >= 17) {
throw new InvalidUserDataException("Groovy $variant is not compatible with Java $javaVersion")
}
} else if (variant == 3.0) {
groovyGroup = "org.codehaus.groovy"
groovyVersion = libs.versions.groovy3.get()
minGroovyVersion = "3.0.0"
maxGroovyVersion = "3.9.99"
} else if (variant == 4.0) {
groovyGroup = "org.apache.groovy"
groovyVersion = libs.versions.groovy4.get()
minGroovyVersion = "4.0.0"
maxGroovyVersion = "4.9.99"
} else {
throw new InvalidUserDataException("Unknown variant: $variant. Choose one of: $variants")
}
groovyDependencies = [
[group: groovyGroup, name: "groovy", version: groovyVersion]
]
groovyConsoleExtraDependencies = [
[group: groovyGroup, name: "groovy-console", version: groovyVersion],
[group: groovyGroup, name: "groovy-test-junit5", version: groovyVersion], // for executing specs
[group: "org.apache.ivy", name: "ivy", version: "2.5.2"] // for @Grab support
]
maxGroovyVersion = snapshotVersion ? "9.9.99" : maxGroovyVersion
if (System.getProperty("groovyVersion")) {
groovyVersion = System.getProperty("groovyVersion")
}
fullVersion = baseVersion + ((!snapshotVersion && milestone) ? "-M$milestone" : "") + "-groovy-$variant" + (snapshotVersion ? "-SNAPSHOT" : '')
variantLessVersion = baseVersion + (snapshotVersion ? "-SNAPSHOT" : (milestone ? "-M$milestone" : ""))
develocity.buildScan.tag "Java $javaVersion"
groovylibs = [
groovy : groovyDependencies,
groovyNio : "$groovyGroup:groovy-nio:$groovyVersion", //for groovy methods on Path
groovySql : "$groovyGroup:groovy-sql:$groovyVersion", //for some Spring and Unitils tests
groovyTest : "$groovyGroup:groovy-test:$groovyVersion", //for @NotYetImplemented
groovyJmx : "$groovyGroup:groovy-jmx:$groovyVersion", //for triggering jacoco dump via jmx
]
}
nohttp {
source.exclude "**/out/**"
source.exclude "**/build*/**"
source.exclude "**/.shelf/**"
}
allprojects {
ext.displayName = null
group = "org.spockframework"
version = fullVersion
apply from: script("common")
// ignore mutable data that is irrelevant for compilation output
normalization {
runtimeClasspath {
metaInf {
ignoreAttribute("Build-Revision")
}
}
}
}
apply from: script("ide")
subprojects {
apply plugin: "java-library"
apply plugin: "groovy"
apply plugin: "jacoco"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
}
tasks.withType(JavaCompile).configureEach {
if (it.name == 'compileJava') {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(8)
}
}
options.encoding = 'UTF-8'
}
tasks.withType(GroovyCompile).configureEach {
options.encoding = 'UTF-8'
}
sourceSets.all { ss ->
for (gv in variants.findAll { variant <= it }) {
java {
srcDir "src/${ss.name}-groovy-le-$gv/java"
}
groovy {
srcDir "src/${ss.name}-groovy-le-$gv/groovy"
}
resources {
srcDir "src/${ss.name}-groovy-le-$gv/resources"
}
}
for (jv in javaVersions.findAll { javaVersion <= it }) {
java {
srcDir "src/${ss.name}-java-le-$jv/java"
}
groovy {
srcDir "src/${ss.name}-java-le-$jv/groovy"
}
resources {
srcDir "src/${ss.name}-java-le-$jv/resources"
}
}
for (gv in variants.findAll { variant >= it }) {
java {
srcDir "src/${ss.name}-groovy-ge-$gv/java"
}
groovy {
srcDir "src/${ss.name}-groovy-ge-$gv/groovy"
}
resources {
srcDir "src/${ss.name}-groovy-ge-$gv/resources"
}
}
for (jv in javaVersions.findAll { javaVersion >= it }) {
java {
srcDir "src/${ss.name}-java-ge-$jv/java"
}
groovy {
srcDir "src/${ss.name}-java-ge-$jv/groovy"
}
resources {
srcDir "src/${ss.name}-java-ge-$jv/resources"
}
}
}
dependencies {
implementation(project.name == "spock-gradle" ? [] : groovylibs.groovy)
}
configureJavadoc(tasks.named("javadoc"))
configureGroovydoc(tasks.named("groovydoc"))
tasks.register("sourcesJar", Jar) {
archiveClassifier = "sources"
from sourceSets.main.allSource
}
tasks.register("javadocJar", Jar) {
archiveClassifier = "javadoc"
from javadoc
}
tasks.withType(Jar).configureEach {
/*
* Ensure the jar can be built in a reproducible manner, This shall prevent build cache misses, when different variants are tested.
*/
preserveFileTimestamps = false
reproducibleFileOrder = true
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
def taskName = name
reports {
junitXml {
outputLocation = file("${outputLocation.get()}/$taskName-$variant")
}
html {
outputLocation = file("${outputLocation.get()}/$taskName-$variant")
}
}
// As a generous general timeout, instead of the 6h of GHA.
timeout = Duration.ofMinutes(15)
}
tasks.register("allDependencyInsight", DependencyInsightReportTask) {}
jacoco {
toolVersion = libs.versions.jacoco.get()
}
}
tasks.register("collectTestXml") {
group = 'Test reports'
description = "Collects the test xmls from every subproject into a new directory with subproject as name."
def reportingProjects = subprojects.findAll()
dependsOn(reportingProjects.tasks.collectMany { it.withType(Test) })
doFirst {
def target = layout.buildDirectory.dir("collected-test-results").get().asFile
target.mkdirs()
reportingProjects.each { rp ->
rp.tasks.withType(Test).each { testTask ->
def repSrc = testTask.reports.junitXml.destination
def repTarget = file("$target/$rp.name-$repSrc.name")
copy {
from repSrc
into repTarget
include '**/*.xml'
}
}
}
}
}
tasks.register("codeCoverageReport", JacocoReport) {
group = 'Coverage reports'
description = "Creates an aggregate coverage for the whole project."
def reportingProjects = subprojects
dependsOn(reportingProjects.tasks.collectMany { it.withType(Test) })
additionalSourceDirs.from(reportingProjects.sourceSets.main.allSource.srcDirs)
additionalClassDirs.from(reportingProjects.sourceSets.main.output)
executionData.from(files(reportingProjects.jacocoTestReport.executionData).filter { it.exists() })
executionData.from(file('spock-specs/build/jacoco/compileTestGroovy.exec'))
reports {
html.required = true
xml.required = true
xml.outputLocation = layout.buildDirectory.file("reports/jacoco/report.xml") // report must be here for codecov to pick it up
csv.required = false
}
}
if (gradle.startParameter.taskNames == ["ghActionsBuild"]) {
gradle.startParameter.taskNames = ["build", "codeCoverageReport"]
}
if (gradle.startParameter.taskNames == ["ghActionsPublish"] || gradle.startParameter.taskNames == ["ghActionsDocs"]) {
def originalStartParameterTaskNames = gradle.startParameter.taskNames
gradle.startParameter.taskNames = []
boolean isMaster = System.getenv("GITHUB_REF") == "refs/heads/master"
boolean isTag = System.getenv("GITHUB_REF")?.startsWith('refs/tags/spock-')
if (!(System.getenv("GITHUB_EVENT_NAME") == "push"
&& (isMaster || isTag)
&& System.getenv("GITHUB_REPOSITORY") == 'spockframework/spock')) {
throw new IllegalArgumentException("""ghActionsPublish can only be run on push to branch master or tag in repo spockframework/spock
event: ${System.getenv("GITHUB_EVENT_NAME")}
ref: ${System.getenv("GITHUB_REF")}
repo: ${System.getenv("GITHUB_REPOSITORY")}""")
}
if (originalStartParameterTaskNames == ["ghActionsPublish"]) {
if (javaVersion != javaVersions.min()) {
throw new IllegalArgumentException("ghActionsPublish can only be run on Java ${javaVersions.min()} but was run on $javaVersion")
}
/*
We want to release only snapshots directly from master, final releases will be tagged and then published from that tag.
*/
if (snapshotVersion) {
gradle.startParameter.taskNames += ["publishToSonatype"]
} else if (isTag) {
gradle.startParameter.taskNames += ["publishToSonatype", "closeSonatypeStagingRepository"]
} // else {
// disable tag release for now as this is done with a token, that doesn't trigger other workflows
// gradle.startParameter.taskNames += ["tagRelease"]
// }
}
if (originalStartParameterTaskNames == ["ghActionsDocs"] && (snapshotVersion || isTag)) {
if (javaVersion != javaVersions.max()) {
throw new IllegalArgumentException("ghActionsPublish can only be run on Java ${javaVersions.max()} but was run on $javaVersion")
}
if (variant != variants.max()) {
throw new IllegalArgumentException("ghActionsPublish can only be run with variant ${variants.max()} but was run with $variant")
}
gradle.startParameter.taskNames += ["publishJavadoc", "publishDocs"]
}
}
tasks.register("publishJavadoc", Exec) {
dependsOn "javadoc"
commandLine "sh", "-c",
"""
git config user.email "[email protected]"
git config user.name "Spock Framework Robot"
git fetch origin +gh-pages:gh-pages
git switch gh-pages
rm -rf javadoc/$variantLessVersion
mkdir -p javadoc/$variantLessVersion
cp -r build/javadoc/$variantLessVersion javadoc/
git add javadoc
git commit -qm "Publish javadoc/$variantLessVersion"
git push "https://\[email protected]/spockframework/spock.git" gh-pages 2>&1 | sed "s/\$GITHUB_TOKEN/xxx/g"
git switch -
"""
}
tasks.register("publishDocs", Exec) {
dependsOn "asciidoctor"
commandLine "sh", "-c",
"""
git config user.email "[email protected]"
git config user.name "Spock Framework Robot"
git fetch origin +gh-pages:gh-pages
git switch gh-pages
rm -rf docs/$variantLessVersion
mkdir -p docs/$variantLessVersion
cp -r build/docs/asciidoc/* docs/$variantLessVersion
git add docs
git commit -qm "Publish docs/$variantLessVersion"
git push "https://\[email protected]/spockframework/spock.git" gh-pages 2>&1 | sed "s/\$GITHUB_TOKEN/xxx/g"
git switch -
"""
}
tasks.register("tagRelease", Exec) {
commandLine "sh", "-c",
"""
git config user.email "[email protected]"
git config user.name "Spock Framework Robot"
git checkout master
git tag -f spock-$variantLessVersion
git push "https://\[email protected]/spockframework/spock.git" spock-$variantLessVersion 2>&1 | sed "s/\$GITHUB_TOKEN/xxx/g"
"""
}
tasks.register("javadoc", Javadoc) {
title "Spock Framework API Documentation ($variantLessVersion)"
destinationDir file("build/javadoc/$variantLessVersion")
source subprojects.collect { project -> project.tasks.named("javadoc").map { it.source } }
classpath = files(subprojects.collect { project -> project.tasks.named("javadoc").map { it.classpath } })
}
configureJavadoc(tasks.named("javadoc"), true)
tasks.register("groovydoc", Groovydoc) {
docTitle "Spock Framework API Documentation ($variantLessVersion)"
windowTitle "Spock Framework API Documentation ($variantLessVersion)"
destinationDir file("build/groovydoc/$variantLessVersion")
source subprojects.collect { project -> project.tasks.named("groovydoc").map { it.source } }
classpath = files(subprojects.collect { project -> project.tasks.named("groovydoc").map { it.classpath } })
groovyClasspath = files(projects.spockCore.dependencyProject.tasks.named("groovydoc").map { it.groovyClasspath })
access = GroovydocAccess.PROTECTED
processScripts = false
includeMainForScripts = false
includeAuthor = false
}
configureGroovydoc(tasks.named("groovydoc"))
configurations {
asciidoctorExtensions
}
dependencies {
// local extension from build-logic/asciidoc-extensions
asciidoctorExtensions 'spockbuild:asciidoc-extensions'
}
asciidoctorj {
version = libs.versions.asciidoctorj
fatalWarnings(missingIncludes())
modules {
diagram.use()
}
}
tasks.named("asciidoctor") {
// work-around for https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/721
dependsOn(project.configurations.asciidoctorExtensions)
configurations 'asciidoctorExtensions'
sourceDir = "docs"
baseDirFollowsSourceDir()
logDocuments = true
attributes "source-highlighter": "coderay", "linkcss": true, "sectanchors": true, "revnumber": variantLessVersion, "commit-ish": System.getenv("GITHUB_SHA") ?: "master"
// also treats the included specs as inputs
inputs.dir file("spock-specs/src/test/groovy/org/spockframework/docs")
inputs.dir file("spock-specs/src/test/resources/snapshots/org/spockframework/docs")
inputs.dir file("spock-spring/src/test/groovy/org/spockframework/spring/docs")
inputs.dir file("spock-spring/src/test/resources/org/spockframework/spring/docs")
inputs.dir file("spock-spring/boot2-test/src/test/groovy/org/spockframework/boot2")
doFirst { verifyAnchorlessCrossDocumentLinks(sourceFileTree) }
doLast { verifyLinksAndAnchors(outputs.files.asFileTree) }
}
nexusPublishing {
packageGroup = 'org.spockframework'
repositories {
sonatype {
username = System.getenv("SONATYPE_OSS_USER")
password = System.getenv("SONATYPE_OSS_PASSWORD")
}
}
transitionCheckOptions {
// closing checks take some time so increase the retries
// total time is maxRetries(180) * delayBetween(10s) = 30m
maxRetries.set(180)
}
}
File script(String name) {
project.file("gradle/${name}.gradle")
}
def configureJavadoc(TaskProvider javadoc, boolean root = false) {
javadoc.configure {
include "spock/**"
configure(options) {
options.addStringOption('Xdoclint:none', '-quiet')
options.noTimestamp()
options.addStringOption('source', '1.8')
links "https://docs.groovy-lang.org/docs/groovy-$groovyVersion/html/gapi/"
links "https://junit.org/junit4/javadoc/latest/"
links "https://javadoc.io/doc/org.mockito/mockito-core/${libs.versions.mockito5.get()}/"
// Use offline package list, as the JavaVersion is fixed to 8 for the time being
// and Hamcrest has certificate issues for their domain.
linksOffline("https://docs.oracle.com/javase/8/docs/api/", "${root ? '' : '../'}javadoc/java-8")
linksOffline("https://hamcrest.org/JavaHamcrest/javadoc/2.2/", "${root ? '' : '../'}javadoc/hamcrest-2.2")
}
}
}
def configureGroovydoc(TaskProvider groovydoc) {
groovydoc.configure {
include "spock/**"
}
}