forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
286 lines (251 loc) · 7.57 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
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")
id("io.github.gradle-nexus.publish-plugin")
}
val buildTimeAndDate: OffsetDateTime 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: String by extra { DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate) }
val buildTime: String by extra { DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ").format(buildTimeAndDate) }
val buildRevision: String by extra { versioning.info.commit }
val builtByValue by extra { project.findProperty("builtBy") ?: project.property("defaultBuiltBy") }
val platformProjects by extra(listOf(
projects.junitPlatformCommons,
projects.junitPlatformConsole,
projects.junitPlatformConsoleStandalone,
projects.junitPlatformEngine,
projects.junitPlatformJfr,
projects.junitPlatformLauncher,
projects.junitPlatformReporting,
projects.junitPlatformRunner,
projects.junitPlatformSuite,
projects.junitPlatformSuiteApi,
projects.junitPlatformSuiteCommons,
projects.junitPlatformSuiteEngine,
projects.junitPlatformTestkit
).map { it.dependencyProject })
val jupiterProjects by extra(listOf(
projects.junitJupiter,
projects.junitJupiterApi,
projects.junitJupiterEngine,
projects.junitJupiterMigrationsupport,
projects.junitJupiterParams
).map { it.dependencyProject })
val vintageProjects by extra(listOf(
projects.junitVintageEngine.dependencyProject
))
val mavenizedProjects by extra(platformProjects + jupiterProjects + vintageProjects)
val modularProjects by extra(mavenizedProjects - listOf(projects.junitPlatformConsoleStandalone.dependencyProject))
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(
projects.junitJupiterEngine,
projects.junitJupiterMigrationsupport,
projects.junitJupiterParams,
projects.junitPlatformRunner,
projects.junitVintageEngine,
projects.platformTests
).map { it.dependencyProject }
val jacocoCoveredProjects = modularProjects
val jacocoClassesDir = file("$buildDir/jacoco/classes")
nexusPublishing {
packageGroup.set("org.junit")
repositories {
sonatype()
}
}
allprojects {
apply(plugin = "eclipse")
apply(plugin = "idea")
apply(plugin = "com.diffplug.spotless")
if (enableJaCoCo) {
apply(plugin = "jacoco")
configure<JacocoPluginExtension> {
toolVersion = rootProject.libs.versions.jacoco.get()
}
}
repositories {
mavenCentral()
maven(url = "https://oss.sonatype.org/content/repositories/snapshots") {
mavenContent {
snapshotsOnly()
}
}
maven(url = "https://jitpack.io") {
mavenContent {
includeModule("com.github.gunnarmorling", "jfrunit")
}
}
}
}
val clearTempRepoDir by tasks.registering {
doFirst {
tempRepoDir.deleteRecursively()
}
}
subprojects {
when (project) {
in jupiterProjects -> {
group = property("jupiterGroup")!!
}
in platformProjects -> {
group = property("platformGroup")!!
version = property("platformVersion")!!
}
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(libs.versions.ktlint.get())
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.archiveFile))
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)
}
}
}
}
tasks.withType<PublishToMavenRepository>().configureEach {
if (name.endsWith("To${tempRepoName.capitalize()}Repository")) {
dependsOn(clearTempRepoDir)
}
}
}
}
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 {
dependsOn(it.tasks.named("extractJar"))
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
}
}
}
}
}