forked from spockframework/spock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
executable file
·419 lines (371 loc) · 14.2 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
import static groovy.io.FileType.FILES
plugins {
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"
}
description = "Spock Framework"
ext {
baseVersion = "2.1"
snapshotVersion = true
milestone = 0
variants = [2.5, 3.0]
variant = System.getProperty("variant") as BigDecimal ?: variants.first()
buildScan.tag "groovy-$variant"
if (variant == 2.5) {
groovyVersion = "2.5.15"
minGroovyVersion = "2.5.0"
maxGroovyVersion = "2.9.99"
} else if (variant == 3.0) {
groovyVersion = "3.0.9"
minGroovyVersion = "3.0.0"
maxGroovyVersion = "3.9.99"
} else {
throw new InvalidUserDataException("Unknown variant: $variant. Choose one of: $variants")
}
groovyDependencies = [
[group: "org.codehaus.groovy", name: "groovy", version: groovyVersion]
]
groovyConsoleExtraDependencies = [
[group: "org.codehaus.groovy", name: "groovy-console", version: groovyVersion],
[group: "org.codehaus.groovy", name: "groovy-test-junit5", version: groovyVersion], // for executing specs
[group: "org.apache.ivy", name: "ivy", version: "2.5.0"] // 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" : ""))
javaVersions = [8, 11, 17] // ensure that latest version is actually build on travis, otherwise no docs get published
javaVersion = (System.getProperty("javaVersion") ?: 8) as int
buildScan.tag "Java $javaVersion"
libs = [
jetbrainsAnnotations: [group: "org.jetbrains", name: "annotations", version: "20.1.0"],
asm : [group: 'org.ow2.asm', name: 'asm', version: '9.2'],
bytebuddy : [group: 'net.bytebuddy', name: 'byte-buddy', version: '1.12.1'],
cglib : [group: 'cglib', name: 'cglib-nodep', version: '3.3.0'],
groovy : groovyDependencies,
groovySql : [group: 'org.codehaus.groovy', name: 'groovy-sql', version: groovyVersion], //for some Spring and Unitils tests
groovyTest : [group: 'org.codehaus.groovy', name: 'groovy-test', version: groovyVersion], //for @NotYetImplemented
groovyJmx : [group: 'org.codehaus.groovy', name: 'groovy-jmx', version: groovyVersion], //for triggering jacoco dump via jmx
h2database : [group: 'com.h2database', name: 'h2', version: '1.4.200'],
hamcrest : [group: 'org.hamcrest', name: 'hamcrest', version: '2.2'],
jaxb : [group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'],
junit4 : [group: 'junit', name: 'junit', version: '4.13.2'],
junitBom : [group: 'org.junit', name: 'junit-bom', version: '5.8.1'],
jupiter : [group: 'org.junit.jupiter', name: 'junit-jupiter'],
junitPlatform : [group: 'org.junit.platform', name: 'junit-platform-engine'],
junitPlatformTestkit: [group: 'org.junit.platform', name: 'junit-platform-testkit'],
junitPlatformConsole: [group: 'org.junit.platform', name: 'junit-platform-console'],
log4j : [group: 'log4j', name: 'log4j', version: '1.2.17'],
objenesis : [group: 'org.objenesis', name: 'objenesis', version: '3.2'],
jacocoAgent : [group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.8.7', classifier: 'runtime']
]
}
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) {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(8)
}
options.encoding = 'UTF-8'
}
tasks.withType(GroovyCompile) {
options.encoding = 'UTF-8'
}
sourceSets.all { ss ->
for (v in variants.findAll { it <= variant } ) {
java {
srcDir "src/${ss.name}$v/java"
}
groovy {
srcDir "src/${ss.name}$v/groovy"
}
}
}
sourceSets.all { ss ->
for (jv in javaVersions.findAll { it <= javaVersion } ) {
java {
srcDir "src/${ss.name}.java$jv/java"
}
groovy {
srcDir "src/${ss.name}.java$jv/groovy"
}
}
}
configurations {
all*.exclude module: "junit-dep"
}
dependencies {
implementation(project.name == "spock-gradle" ? [] : libs.groovy)
}
configureJavadoc(javadoc)
configureGroovydoc(groovydoc)
task sourcesJar(type: Jar) {
classifier "sources"
from sourceSets.main.allSource
}
task javadocJar(type: Jar) {
classifier "javadoc"
from javadoc
}
def javaVersionNoShadow = javaVersion // Test task also has javaVersion
tasks.withType(Test) {
useJUnitPlatform()
def taskName = name
reports {
junitXml {
destination = file("$destination/$taskName-$variant")
}
html {
destination = file("$destination/$taskName-$variant")
}
}
//Required for building on Travis' container-based infrastructure to not be killed with
//'exit code 137' - https://github.com/travis-ci/travis-ci/issues/5582
jvmArgs '-Xmx512m'
if (javaVersionNoShadow >= 17) {
// Workaround for Java 17 to enable mocking of default methods
jvmArgs("--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED")
}
}
jacoco {
toolVersion = libs.jacocoAgent.version
}
}
task 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 = file("$buildDir/collected-test-results")
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'
}
}
}
}
}
task codeCoverageReport (type: 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.enabled = true
xml.enabled = true
xml.destination file("${buildDir}/reports/jacoco/report.xml") // report must be here for codecov to pick it up
csv.enabled = 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"]
}
}
task publishJavadoc(type: Exec) {
dependsOn "javadoc"
commandLine "sh", "-c",
"""
git config user.email "dev@forum.spockframework.org"
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://\$GITHUB_TOKEN@github.com/spockframework/spock.git" gh-pages 2>&1 | sed "s/\$GITHUB_TOKEN/xxx/g"
git switch -
"""
}
task publishDocs(type: Exec) {
dependsOn "asciidoctor"
commandLine "sh", "-c",
"""
git config user.email "dev@forum.spockframework.org"
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://\$GITHUB_TOKEN@github.com/spockframework/spock.git" gh-pages 2>&1 | sed "s/\$GITHUB_TOKEN/xxx/g"
git switch -
"""
}
task tagRelease(type: Exec) {
commandLine "sh", "-c",
"""
git config user.email "dev@forum.spockframework.org"
git config user.name "Spock Framework Robot"
git checkout master
git tag -f spock-$variantLessVersion
git push "https://\$GITHUB_TOKEN@github.com/spockframework/spock.git" spock-$variantLessVersion 2>&1 | sed "s/\$GITHUB_TOKEN/xxx/g"
"""
}
task javadoc(type: Javadoc) {
title "Spock Framework API Documentation ($variantLessVersion)"
destinationDir file("build/javadoc/$variantLessVersion")
source subprojects.javadoc.source
classpath = files(subprojects.javadoc.classpath)
}
configureJavadoc(javadoc)
task groovydoc(type: Groovydoc) {
docTitle "Spock Framework API Documentation ($variantLessVersion)"
windowTitle "Spock Framework API Documentation ($variantLessVersion)"
destinationDir file("build/groovydoc/$variantLessVersion")
source subprojects.groovydoc.source
classpath = files(subprojects.groovydoc.classpath)
groovyClasspath = project(":spock-core").groovydoc.groovyClasspath
}
configureGroovydoc(groovydoc)
asciidoctorj {
modules {
diagram.use()
}
}
asciidoctor {
sourceDir = "docs"
baseDirFollowsSourceDir()
logDocuments = true
attributes "source-highlighter": "coderay", "linkcss": true, "sectanchors": true, "revnumber": variantLessVersion
// also treats the included specs as inputs
inputs.dir file("spock-specs/src/test/groovy/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")
inputs.dir file("spock-spring/spring3-test/src/test/groovy/org/spockframework/spring3")
inputs.dir file("spock-spring/spring5-test/src/test/groovy/org/spockframework/spring5")
doFirst {
def errors = []
sourceDir.eachFileRecurse(FILES) { file ->
if (file.name =~ /(?<!^index)\.adoc$/) {
(file.text =~ /<<([^>#]+\.adoc)#,[^>]+>>/)
.collect { it[1] }
.unique()
.each {
errors << "$file.name contains a cross-document link to $it without anchor, this will break in one-page variant"
}
}
}
if (errors) {
throw new IllegalArgumentException(errors.join('\n'))
}
}
}
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(task) {
configure(task) {
include "spock/**"
configure(options) {
options.addStringOption('Xdoclint:none', '-quiet')
options.noTimestamp()
options.addStringOption('source', '1.8')
links "https://docs.oracle.com/javase/8/docs/api/"
links "https://docs.groovy-lang.org/docs/groovy-$groovyVersion/html/gapi/"
links "https://junit.org/junit4/javadoc/latest/"
links "http://hamcrest.org/JavaHamcrest/javadoc/2.2/"
}
}
}
def configureGroovydoc(task) {
configure(task) {
include "spock/**"
}
}
subprojects {
task allDependencyInsight(type: DependencyInsightReportTask) {}
}