forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
216 lines (191 loc) · 5.82 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
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") // gradle dependencyUpdates
id("com.diffplug.gradle.spotless")
id("de.marcphilipp.nexus-publish") apply false
id("io.spring.nohttp")
}
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
val buildTimeAndDate = 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-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 enableJaCoCo = project.hasProperty("enableJaCoCo")
val jacocoTestProjects = listOf(
project(":junit-jupiter-engine"),
project(":junit-jupiter-migrationsupport"),
project(":junit-jupiter-params"),
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.gradle.spotless")
if (enableJaCoCo) {
apply(plugin = "jacoco")
configure<JacocoPluginExtension> {
toolVersion = Versions.jacoco
}
}
repositories {
// mavenLocal()
mavenCentral()
maven(url = "https://oss.sonatype.org/content/repositories/snapshots") {
mavenContent {
snapshotsOnly()
}
}
}
}
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")!!
}
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)
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)
}
}
}
}
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 {
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
}
}
}
}
}