forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
484 lines (416 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
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
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
plugins {
id 'com.gradle.build-scan'
id 'net.nemerosa.versioning'
id 'com.github.ben-manes.versions' apply false
id 'com.diffplug.gradle.spotless' apply false
id 'org.ajoberstar.git-publish' apply false
id 'org.jetbrains.kotlin.jvm' apply false
}
buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
}
def buildTimeAndDate = OffsetDateTime.now()
ext {
// Generate JAR manifest only if code was compiled or recompiled;
// otherwise the junitPlatformTest task will always be executed even if
// no code changes were made. The reason is that the generation of
// the buildDate and buildTime causes JAR manifests to be modified
// which triggers unnecessary rebuilding of the dependent JARs.
generateManifest = false
buildDate = DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate)
buildTime = DateTimeFormatter.ofPattern('HH:mm:ss.SSSZ').format(buildTimeAndDate)
buildRevision = versioning.info.commit
builtByValue = project.hasProperty('builtBy') ? project.builtBy : project.defaultBuiltBy
docsVersion = project.version.contains('SNAPSHOT') ? 'snapshot' : project.version
platformProjects = [
'junit-platform-commons',
'junit-platform-console',
'junit-platform-console-standalone',
'junit-platform-engine',
'junit-platform-launcher',
'junit-platform-runner',
'junit-platform-suite-api',
'junit-platform-testkit'
]
jupiterProjects = [
'junit-jupiter-api',
'junit-jupiter-engine',
'junit-jupiter-migrationsupport',
'junit-jupiter-params'
]
vintageProjects = [
'junit-vintage-engine'
]
mavenizedProjects = platformProjects + jupiterProjects + vintageProjects
license = [
name: 'Eclipse Public License v2.0',
url: 'http://www.eclipse.org/legal/epl-v20.html',
headerFile: 'eclipse-public-license-2.0.java'
]
jacocoTestProjects = [
'junit-jupiter-engine',
'junit-jupiter-migrationsupport',
'junit-jupiter-params',
'junit-vintage-engine',
'platform-tests'
]
jacocoCoveredProjects = mavenizedProjects - ['junit-platform-console-standalone']
jacocoClassesDir = "$buildDir/jacoco/classes"
}
allprojects { subproj ->
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.diffplug.gradle.spotless'
apply plugin: 'checkstyle'
apply plugin: 'com.github.ben-manes.versions' // gradle dependencyUpdates
if (project.hasProperty('enableJaCoCo')) {
apply plugin: 'jacoco'
jacoco {
toolVersion = Versions.jacoco
}
}
repositories {
// mavenLocal()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
api("org.apiguardian:apiguardian-api:${Versions.apiGuardian}")
}
compileJava {
options.encoding = 'UTF-8'
// See: https://docs.oracle.com/javase/10/tools/javac.htm
options.compilerArgs += [
'-Xlint', // Enables all recommended warnings.
'-Werror' // Terminates compilation when warnings occur.
]
}
compileTestJava {
options.encoding = 'UTF-8'
sourceCompatibility = 10
targetCompatibility = 10
// See: https://docs.oracle.com/javase/10/tools/javac.htm
options.compilerArgs += [
'-Xlint', // Enables all recommended warnings.
'-Xlint:-overrides', // Disables "method overrides" warnings.
'-parameters' // Generates metadata for reflection on method parameters.
]
}
// Declare "javacRelease" as a global property to make it overridable by
// a sub-project.
ext.javacRelease = Versions.jvmTarget
subproj.afterEvaluate { evaluatedProject ->
evaluatedProject.tasks.getByName('compileJava') {
sourceCompatibility = javacRelease
targetCompatibility = javacRelease // needed by asm
// --release release
// Compiles against the public, supported and documented API for a specific VM version.
// Supported release targets are 6, 7, 8, 9, 10, and 11.
// Note that if --release is added then -target and -source are ignored.
options.compilerArgs += ['--release', javacRelease]
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions {
jvmTarget = "1.${Versions.jvmTarget}"
apiVersion = '1.1'
languageVersion = '1.1'
}
}
checkstyle {
toolVersion = Versions.checkstyle
configDir = rootProject.file('src/checkstyle')
}
checkstyleMain {
configFile = rootProject.file('src/checkstyle/checkstyleMain.xml')
}
checkstyleTest {
configFile = rootProject.file('src/checkstyle/checkstyleTest.xml')
}
}
subprojects { subproj ->
if (subproj.name in jupiterProjects) {
subproj.group = jupiterGroup
}
else if (subproj.name in platformProjects) {
subproj.group = platformGroup
subproj.version = platformVersion
}
else if (subproj.name in vintageProjects) {
subproj.group = vintageGroup
subproj.version = vintageVersion
}
configurations {
shadowed
}
sourceSets {
main.compileClasspath += configurations.shadowed
test.runtimeClasspath += configurations.shadowed
}
eclipse {
classpath {
plusConfigurations += [ configurations.shadowed ]
}
}
idea {
module {
scopes.PROVIDED.plus += [ configurations.shadowed ]
}
}
javadoc {
classpath = project.sourceSets.main.compileClasspath + configurations.shadowed
}
checkstyleMain {
classpath += configurations.shadowed
}
if (subproj.name in mavenizedProjects) {
apply from: "$rootDir/gradle/publishing.gradle"
apply from: "$rootDir/gradle/japicc.gradle"
javadoc {
options {
memberLevel = JavadocMemberLevel.PROTECTED
author = true
header = project.name
use = true
addBooleanOption('Xdoclint:html,syntax', true)
addBooleanOption('html5', true)
addMultilineStringsOption('tag').value = [
'apiNote:a:API Note:',
'implNote:a:Implementation Note:'
]
encoding = 'UTF-8'
noTimestamp = true
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
tasks.withType(Jar) {
from(project.rootDir) {
include 'LICENSE.md'
include 'LICENSE-notice.md'
into 'META-INF'
}
}
publishing.publications.maven {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
description = "Module \"${project.name}\" of JUnit 5." as String
}
}
} else {
jar.enabled = false
javadoc.enabled = false
}
def normalizeVersion = { versionLiteral ->
try {
(versionLiteral =~ /(\d+)\.(\d+)\.(\d+).*/)[0][1..3].join('.')
} catch(x) {
throw new GradleException("Version '$versionLiteral' does not match version pattern, e.g. 5.0.0-QUALIFIER", x)
}
}
compileJava.doLast {
// Enable JAR manifest generation
generateManifest = true
}
jar {
onlyIf {
project.generateManifest
}
manifest {
attributes(
'Created-By': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})".toString(),
'Built-By': builtByValue,
'Build-Date': buildDate,
'Build-Time': buildTime,
'Build-Revision': buildRevision,
'Specification-Title': project.name,
'Specification-Version': normalizeVersion(project.version),
'Specification-Vendor': 'junit.org',
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': 'junit.org'
)
}
// If available, compile and include classes for other Java versions.
['9'].each { version ->
def versionedName = project.name + '-java-' + version
def versionedProject = findProject(':' + versionedName)
if (versionedProject == null) {
return
}
// We're only interested in the compiled classes. So we depend
// on the classes task and change (-C) to the destination
// directory of the version-aware project later.
dependsOn = [versionedProject.classes]
doLast {
// The following two external "project.exec" commands should be replaced by:
// ToolProvider.findFirst("jar").get().run(System.out, System.err,
// '--update',
// '--file', archivePath,
// '--release', version,
// '-C', versionedProject.compileJava.destinationDir,
// '.')
// Blocked by: https://github.com/gradle/gradle/issues/721
project.exec {
executable "${System.properties['java.home']}/bin/jar"
args = ['--version']
}
project.exec {
executable "${System.properties['java.home']}/bin/jar"
args = ['--update','--file', archivePath,
'--release', version,
'-C', versionedProject.compileJava.destinationDir,
'.'
]
}
}
}
}
spotless {
def headerFile = rootProject.file('src/spotless/' + license['headerFile'])
def importOrderConfigFile = rootProject.file('src/eclipse/junit-eclipse.importorder')
def javaFormatterConfigFile = rootProject.file('src/eclipse/junit-eclipse-formatter-settings.xml')
java {
licenseHeaderFile headerFile, '(package|import|open|module) '
importOrderFile importOrderConfigFile
eclipse().configFile javaFormatterConfigFile
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
ktlint(Versions.ktlint)
licenseHeaderFile headerFile
trimTrailingWhitespace()
endWithNewline()
}
}
afterEvaluate {
if (project.hasProperty('enableJaCoCo')) {
if (subproj.name in jacocoTestProjects) {
jacoco {
applyTo subproj.tasks.matching { it.name == 'junitPlatformTest' }
}
}
if (subproj.name in jacocoCoveredProjects) {
def jarTask = subproj.tasks.findByName('shadowJar') ?: subproj.jar
task extractJar(type: Copy) {
from zipTree(jarTask.archivePath)
into jacocoClassesDir
include '**/*.class'
// don't report coverage for shadowed classes
exclude '**/shadow/**'
// don't version-specific classes of MR JARs
exclude 'META-INF/versions/**'
includeEmptyDirs = false
onlyIf { jarTask.enabled }
}
jarTask.finalizedBy(extractJar)
}
}
}
}
configure(rootProject) {
description = 'JUnit 5'
apply from: "$rootDir/gradle/gh-pages.gradle"
jar.enabled = false
def ota4jDocVersion = Versions.ota4j.contains('SNAPSHOT') ? 'snapshot' : Versions.ota4j
def apiGuardianDocVersion = Versions.apiGuardian.contains('SNAPSHOT') ? 'snapshot' : Versions.apiGuardian
task aggregateJavadocs(type: Javadoc) {
group = 'Documentation'
description = 'Generates aggregated Javadocs'
dependsOn subprojects.collect { it.tasks.getByName('jar') }
title = "JUnit ${version} API"
options {
memberLevel = JavadocMemberLevel.PROTECTED
author = true
header = rootProject.description
use = true
splitIndex = true
addBooleanOption('Xdoclint:none', true)
addBooleanOption('html5', true)
addMultilineStringsOption('tag').value = [
'apiNote:a:API Note:',
'implNote:a:Implementation Note:'
]
encoding = 'UTF-8'
noTimestamp = true
JFlags = ['-Xmx1g']
links('https://docs.oracle.com/javase/8/docs/api/')
links("https://ota4j-team.github.io/opentest4j/docs/${ota4jDocVersion}/api/")
links("https://apiguardian-team.github.io/apiguardian/docs/${apiGuardianDocVersion}/api/")
stylesheetFile = rootProject.file('src/javadoc/stylesheet.css')
groups = [
Jupiter: ['org.junit.jupiter.*'],
Vintage: ['org.junit.vintage.*'],
Platform: ['org.junit.platform.*']
]
}
// Only generate JavaDoc for 'main' sources in Mavenized projects
source = subprojects.findAll { mavenizedProjects.contains(it.name) }.collect { it.sourceSets.main.allJava }
maxMemory = '1024m'
destinationDir = new File(buildDir, 'docs/javadoc')
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
// Remove Kotlin classes from classpath due to "bad" class file
// see https://bugs.openjdk.java.net/browse/JDK-8187422
.filter { !it.path.contains('kotlin') }
// Remove subproject JARs so Kotlin classes don't get picked up
.filter { it.isDirectory() || !it.absolutePath.startsWith(projectDir.absolutePath) }
}
spotless {
format 'misc', {
target '**/*.gradle', '**/*.gradle.kts', '**/*.gitignore'
indentWithTabs()
trimTrailingWhitespace()
endWithNewline()
}
format 'documentation', {
target '**/*.adoc', '**/*.md'
trimTrailingWhitespace()
endWithNewline()
}
}
if (project.hasProperty('enableJaCoCo')) {
task jacocoMerge(type: JacocoMerge) {
subprojects.findAll { it.name in jacocoTestProjects }
.each { subproj ->
executionData fileTree(dir: "${subproj.buildDir}/jacoco", include: '*.exec')
dependsOn subproj.tasks.withType(Test)
}
}
task jacocoRootReport(type: JacocoReport, dependsOn: jacocoMerge) {
sourceDirectories = files(subprojects
.findAll { it.name in jacocoCoveredProjects }
.sourceSets.main.allSource.srcDirs)
classDirectories = files(jacocoClassesDir)
executionData jacocoMerge.destinationFile
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
}
wrapper {
gradleVersion = '4.10.2'
/*
* Reasoning for using BIN:
* https://github.com/junit-team/junit5/pull/1012#discussion_r132061924
*/
distributionType = Wrapper.DistributionType.BIN
}