forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
263 lines (229 loc) · 7.02 KB
/
build.gradle.kts
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
import java.time.OffsetDateTime
import java.time.Instant
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
plugins {
id("net.nemerosa.versioning")
id("com.github.ben-manes.versions") // gradle dependencyUpdates
id("com.diffplug.spotless")
id("io.spring.nohttp")
}
apply(from = "gradle/build-scan-user-data.gradle")
val buildTimeAndDate by extra {
// SOURCE_DATE_EPOCH is a UNIX timestamp for pinning build metadata against
// in order to achieve reproducible builds
//
// More details - https://reproducible-builds.org/docs/source-date-epoch/
if (System.getenv().containsKey("SOURCE_DATE_EPOCH")) {
val sourceDateEpoch = System.getenv("SOURCE_DATE_EPOCH").toLong()
Instant.ofEpochSecond(sourceDateEpoch).atOffset(ZoneOffset.UTC)
} else {
OffsetDateTime.now()
}
}
val buildDate by extra { DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate) }
val buildTime by extra { DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ").format(buildTimeAndDate) }
val buildRevision by extra { versioning.info.commit }
val builtByValue by extra { project.findProperty("builtBy") ?: project.property("defaultBuiltBy") }
val platformProjects by extra(listOf(
project(":junit-platform-commons"),
project(":junit-platform-console"),
project(":junit-platform-console-standalone"),
project(":junit-platform-engine"),
project(":junit-platform-jfr"),
project(":junit-platform-launcher"),
project(":junit-platform-reporting"),
project(":junit-platform-runner"),
project(":junit-platform-suite-api"),
project(":junit-platform-testkit")
))
val jupiterProjects by extra(listOf(
project(":junit-jupiter"),
project(":junit-jupiter-api"),
project(":junit-jupiter-engine"),
project(":junit-jupiter-migrationsupport"),
project(":junit-jupiter-params")
))
val vintageProjects by extra(listOf(
project(":junit-vintage-engine")
))
val mavenizedProjects by extra(platformProjects + jupiterProjects + vintageProjects)
val modularProjects by extra(mavenizedProjects - listOf(project(":junit-platform-console-standalone")))
val license by extra(License(
name = "Eclipse Public License v2.0",
url = uri("https://www.eclipse.org/legal/epl-v20.html"),
headerFile = file("src/spotless/eclipse-public-license-2.0.java")
))
val tempRepoName by extra("temp")
val tempRepoDir by extra(file("$buildDir/repo"))
val enableJaCoCo = project.hasProperty("enableJaCoCo")
val jacocoTestProjects = listOf(
project(":junit-jupiter-engine"),
project(":junit-jupiter-migrationsupport"),
project(":junit-jupiter-params"),
project(":junit-platform-runner"),
project(":junit-vintage-engine"),
project(":platform-tests")
)
val jacocoCoveredProjects = modularProjects
val jacocoClassesDir = file("$buildDir/jacoco/classes")
allprojects {
apply(plugin = "eclipse")
apply(plugin = "idea")
apply(plugin = "com.diffplug.spotless")
if (enableJaCoCo) {
apply(plugin = "jacoco")
configure<JacocoPluginExtension> {
toolVersion = versions["jacoco"]
}
}
repositories {
mavenCentral()
maven(url = "https://oss.sonatype.org/content/repositories/snapshots") {
mavenContent {
snapshotsOnly()
}
}
maven(url = "https://jitpack.io") {
mavenContent {
includeModule("com.github.gunnarmorling", "jfrunit")
}
}
}
}
subprojects {
if (project in jupiterProjects) {
group = property("jupiterGroup")!!
}
else if (project in platformProjects) {
group = property("platformGroup")!!
version = property("platformVersion")!!
}
else if (project in vintageProjects) {
group = property("vintageGroup")!!
version = property("vintageVersion")!!
}
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
dirMode = Integer.parseInt("0755", 8)
fileMode = Integer.parseInt("0644", 8)
}
pluginManager.withPlugin("java") {
spotless {
val headerFile = license.headerFile
val importOrderConfigFile = rootProject.file("src/eclipse/junit-eclipse.importorder")
val javaFormatterConfigFile = rootProject.file("src/eclipse/junit-eclipse-formatter-settings.xml")
java {
licenseHeaderFile(headerFile, "(package|import|open|module) ")
importOrderFile(importOrderConfigFile)
eclipse().configFile(javaFormatterConfigFile)
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_15)) {
// Doesn't work with Java 15 text blocks, see https://github.com/diffplug/spotless/issues/713
removeUnusedImports()
}
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
ktlint(versions["ktlint"])
licenseHeaderFile(headerFile)
trimTrailingWhitespace()
endWithNewline()
}
}
afterEvaluate {
if (enableJaCoCo && project in jacocoCoveredProjects) {
val jarTask = (tasks.findByName("shadowJar") ?: tasks["jar"]) as Jar
val extractJar by tasks.registering(Copy::class) {
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)
}
}
}
pluginManager.withPlugin("maven-publish") {
configure<PublishingExtension> {
repositories {
repositories {
maven {
name = tempRepoName
url = uri(tempRepoDir)
}
}
}
}
}
}
rootProject.apply {
description = "JUnit 5"
spotless {
format("misc") {
target("**/*.gradle", "**/*.gradle.kts", "**/*.gitignore")
targetExclude("**/build/**")
indentWithTabs()
trimTrailingWhitespace()
endWithNewline()
}
format("documentation") {
target("**/*.adoc", "**/*.md")
trimTrailingWhitespace()
endWithNewline()
}
}
nohttp {
// Must cast, since `source` is only exposed as a FileTree
(source as ConfigurableFileTree).exclude("buildSrc/build/generated-sources/**")
}
tasks {
dependencyUpdates {
checkConstraints = true
resolutionStrategy {
componentSelection {
all {
val rejected = listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea")
.map { qualifier -> Regex("(?i).*[.-]$qualifier[.\\d-+]*") }
.any { it.matches(candidate.version) }
if (rejected) {
reject("Release candidate")
}
}
}
}
}
}
if (enableJaCoCo) {
tasks {
val jacocoMerge by registering(JacocoMerge::class) {
subprojects.filter { it in jacocoTestProjects }
.forEach { subproj ->
executionData(fileTree("dir" to "${subproj.buildDir}/jacoco", "include" to "*.exec"))
dependsOn(subproj.tasks.withType<Test>())
}
}
register<JacocoReport>("jacocoRootReport") {
dependsOn(jacocoMerge)
jacocoCoveredProjects.forEach {
it.pluginManager.withPlugin("java") {
sourceDirectories.from(it.the<SourceSetContainer>()["main"].allSource.srcDirs)
}
}
classDirectories.from(files(jacocoClassesDir))
executionData(jacocoMerge.get().destinationFile)
reports {
html.isEnabled = true
xml.isEnabled = true
csv.isEnabled = false
}
}
}
}
}