forked from spockframework/spock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
executable file
·409 lines (361 loc) · 13 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
import static groovy.io.FileType.FILES
plugins {
id "base"
id "org.asciidoctor.jvm.convert"
id "jacoco"
id "net.nemerosa.versioning"
id "de.marcphilipp.nexus-publish" apply false
id "com.github.ben-manes.versions"
}
description = "Spock Framework"
ext {
baseVersion = "2.0"
snapshotVersion = true
milestone = 0
variants = [2.5, 3.0]
variant = System.getProperty("variant") as BigDecimal ?: variants.first()
if (variant == 2.5) {
groovyVersion = "2.5.12"
minGroovyVersion = "2.5.0"
maxGroovyVersion = "2.9.99"
} else if (variant == 3.0) {
groovyVersion = "3.0.4"
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 = [1.8, 11, 14] // ensure that latest version is actually build on travis, otherwise no docs get published
javaVersion = System.getProperty("java.specification.version") as BigDecimal
libs = [
jetbrainsAnnotations: [group: "org.jetbrains", name: "annotations", version: "19.0.0"],
asm : [group: 'org.ow2.asm', name: 'asm', version: '8.0.1'],
bytebuddy : [group: 'net.bytebuddy', name: 'byte-buddy', version: '1.10.10'],
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
h2database : [group: 'com.h2database', name: 'h2', version: '1.4.200'],
hamcrest : [group: 'org.hamcrest', name: 'hamcrest-core', version: '2.2'],
jaxb : [group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'],
junit4 : [group: 'junit', name: 'junit', version: '4.13'],
junitBom : [group: 'org.junit', name: 'junit-bom', version: '5.7.0-M1'],
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.1']
]
}
allprojects {
ext.displayName = null
group = "org.spockframework"
version = fullVersion
apply from: script("common")
if (javaVersion == 1.8) {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.noTimestamp()
}
} else if (javaVersion >= 9){
tasks.withType(JavaCompile) {
sourceCompatibility = javaVersions.min()
targetCompatibility = javaVersions.min()
options.compilerArgs += ['--release', '8']
options.encoding = 'UTF-8'
}
tasks.withType(GroovyCompile) {
sourceCompatibility = javaVersions.min()
targetCompatibility = javaVersions.min()
options.compilerArgs += ['--release', '8']
options.encoding = 'UTF-8'
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.noTimestamp()
}
}
}
apply from: script("ide")
allprojects {
repositories {
mavenCentral()
maven {
url 'https://jitpack.io'
content {
includeGroup "com.github.junit-team.junit5"
}
}
}
}
subprojects {
apply plugin: "groovy"
apply plugin: "jacoco"
sourceCompatibility = javaVersions.min()
targetCompatibility = javaVersions.min()
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 {
compile(platform(libs.junitBom))
compile(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
}
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'
//Workaround on https://github.com/junit-team/junit5/issues/1909 - to be removed once switched to junit 5.6
afterSuite { desc, result ->
if (!desc.parent) {
if (result.testCount == 0) {
throw new IllegalStateException("No tests were found. Failing the build")
}
}
}
}
jacoco {
toolVersion = '0.8.5'
}
}
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() })
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 == ["travisCiBuild"]) {
gradle.startParameter.taskNames = ["build", "codeCoverageReport"]
subprojects {
tasks.withType(Test) {
maxParallelForks = 2
}
}
if (System.getenv("TRAVIS_PULL_REQUEST") == "false" && System.getenv("TRAVIS_BRANCH") == "master") {
if (javaVersion == javaVersions.min()) {
gradle.startParameter.taskNames += ["publish"]
if (!snapshotVersion) {
gradle.startParameter.taskNames += ["tagRelease"]
}
}
if (javaVersion == javaVersions.max()) {
if (variant == variants.max()) {
gradle.startParameter.taskNames += ["publishJavadoc", "publishDocs"]
}
}
}
}
if (gradle.startParameter.taskNames == ["shippableCiBuild"]) {
gradle.startParameter.taskNames = ["clean", "build"] // use clean because whole minion is cached
task aggregateTestResults(type: Sync) {
from { subprojects.test.reports.junitXml.destination }
into "shippable/testresults"
include "**/TEST-*.xml"
}
subprojects {
tasks.withType(Test) {
it.finalizedBy(aggregateTestResults)
}
}
}
if (gradle.startParameter.taskNames == ["appveyorCiBuild"]) {
gradle.startParameter.taskNames = ["build"]
}
if (gradle.startParameter.taskNames == ["circleCiBuild"]) {
gradle.startParameter.taskNames = ["build", "collectTestXml"]
}
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 checkout 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 checkout master
"""
}
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 checkout 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 checkout master
"""
}
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)
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/boot-test/src/test/groovy/org/spockframework/boot")
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'))
}
}
}
File script(String name) {
project.file("gradle/${name}.gradle")
}
def configureJavadoc(task) {
configure(task) {
include "spock/**"
configure(options) {
options.addStringOption('source', '1.8')
links "http://docs.oracle.com/javase/8/docs/api/"
links "http://docs.groovy-lang.org/docs/groovy-$groovyVersion/html/gapi/"
links "http://junit.org/junit4/javadoc/latest/"
links "http://hamcrest.org/JavaHamcrest/javadoc/1.3/"
}
}
}
def configureGroovydoc(task) {
configure(task) {
include "spock/**"
}
}
subprojects {
task allDependencyInsight(type: DependencyInsightReportTask) {}
}