forked from junit-pioneer/junit-pioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
366 lines (317 loc) · 10.8 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
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
plugins {
java
jacoco
checkstyle
`maven-publish`
signing
id("com.diffplug.spotless") version "6.25.0"
id("at.zierler.yamlvalidator") version "1.5.0"
id("org.sonarqube") version "5.1.0.4882"
id("org.shipkit.shipkit-changelog") version "2.0.1"
id("org.shipkit.shipkit-github-release") version "2.0.1"
id("com.github.ben-manes.versions") version "0.51.0"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("org.gradlex.extra-java-module-info") version "1.9"
}
plugins.withType<JavaPlugin>().configureEach {
configure<JavaPluginExtension> {
modularity.inferModulePath.set(true)
}
}
group = "org.junit-pioneer"
description = "JUnit 5 Extension Pack"
val experimentalJavaVersion : String? by project
val experimentalBuild: Boolean = experimentalJavaVersion?.isNotEmpty() ?: false
val releaseBuild : Boolean = project.version != "unspecified"
val targetJavaVersion = JavaVersion.VERSION_11
java {
if (experimentalBuild) {
toolchain {
languageVersion.set(JavaLanguageVersion.of(experimentalJavaVersion!!))
}
} else {
sourceCompatibility = targetJavaVersion
}
withJavadocJar()
withSourcesJar()
registerFeature("jackson") {
usingSourceSet(sourceSets["main"])
}
}
repositories {
mavenCentral()
}
val junitVersion : String by project
val jacksonVersion: String = "2.18.0"
val assertjVersion: String = "3.26.3"
val jimfsVersion: String = "1.3.0"
dependencies {
implementation(platform("org.junit:junit-bom:$junitVersion"))
implementation(group = "org.junit.jupiter", name = "junit-jupiter-api")
implementation(group = "org.junit.jupiter", name = "junit-jupiter-params")
implementation(group = "org.junit.platform", name = "junit-platform-launcher")
"jacksonImplementation"(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = jacksonVersion)
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-engine")
testImplementation(group = "org.junit.platform", name = "junit-platform-testkit")
testImplementation(group = "org.assertj", name = "assertj-core", version = assertjVersion)
testImplementation(group = "org.mockito", name = "mockito-core", version = "5.14.1")
testImplementation(group = "com.google.jimfs", name = "jimfs", version = jimfsVersion)
testImplementation(group = "nl.jqno.equalsverifier", name = "equalsverifier", version = "3.17.1")
}
spotless {
val headerFile = file(".infra/spotless/eclipse-public-license-2.0.java")
java {
licenseHeaderFile(headerFile, "(package|import) ")
importOrderFile(file(".infra/eclipse/junit-eclipse.importorder"))
eclipse().configFile(".infra/eclipse/junit-eclipse-formatter-settings.xml")
trimTrailingWhitespace()
endWithNewline()
}
}
checkstyle {
toolVersion = "10.18.2"
configDirectory.set(rootProject.file(".infra/checkstyle"))
}
yamlValidator {
searchPaths = listOf("docs")
isSearchRecursive = true
}
jacoco {
toolVersion = "0.8.12"
}
sonar {
// If you want to use this locally a sonarLogin has to be provided, either via Username and Password
// or via token, https://docs.sonarqube.org/latest/analysis/analysis-parameters/
properties {
// Default properties if somebody wants to execute it locally
property("sonar.projectKey", "junit-pioneer_junit-pioneer") // needs to be changed
property("sonar.organization", "junit-pioneer-xp") // needs to be changed
property("sonar.host.url", "https://sonarcloud.io")
}
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
// additional pom content
pom {
name.set(project.name)
description.set(project.description)
url.set("https://junit-pioneer.org/")
licenses {
license {
name.set("Eclipse Public License v2.0")
url.set("https://www.eclipse.org/legal/epl-v20.html")
}
}
scm {
url.set("https://github.com/junit-pioneer/junit-pioneer.git")
}
issueManagement {
system.set("GitHub Issues")
url.set("https://github.com/junit-pioneer/junit-pioneer/issues")
}
ciManagement {
system.set("GitHub Actions")
url.set("https://github.com/junit-pioneer/junit-pioneer/actions")
}
developers {
mapOf(
"nipafx" to "Nicolai Parlog",
"Bukama" to "Matthias Bünger",
"aepfli" to "Simon Schrottner",
"Michael1993" to "Mihály Verhás",
"beatngu13" to "Daniel Kraus"
).forEach {
developer {
id.set(it.key)
name.set(it.value)
url.set("https://github.com/" + it.key)
}
}
}
}
}
}
}
signing {
isRequired = releaseBuild && gradle.taskGraph.hasTask("publishToSonatype")
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications.findByName("maven"))
}
nexusPublishing {
repositories {
sonatype()
}
}
extraJavaModuleInfo {
failOnMissingModuleInfo.set(false)
automaticModule("com.google.guava:failureaccess", "com.google.guava.failureaccess")
automaticModule("com.google.guava:listenablefuture", "com.google.guava.listenablefuture")
automaticModule("com.google.code.findbugs:jsr305", "com.google.code.findbugs.jsr305")
automaticModule("com.google.j2objc:j2objc-annotations", "com.google.j2objc.annotations")
}
tasks {
sourceSets {
create("demo") {
java {
srcDir("src/demo/java")
}
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
}
// Adds all dependencies of main to demo sourceSet
configurations["demoImplementation"].extendsFrom(configurations.testImplementation.get())
// Ensures JUnit 5 engine is available to demo at runtime
configurations["demoRuntimeOnly"].extendsFrom(configurations.testImplementation.get())
compileJava {
options.encoding = "UTF-8"
options.compilerArgs.add("-Werror")
// Do not break the build on "exports" warnings (see CONTRIBUTING.adoc for details)
options.compilerArgs.add("-Xlint:all,-exports")
if (project.version != "unspecified") {
// Add version to Java modules
options.javaModuleVersion.set(project.version.toString())
}
}
// Prepares test-related JVM args
val moduleName = "org.junitpioneer"
// See https://docs.gradle.org/current/userguide/java_testing.html#sec:java_testing_modular_patching
val patchModuleArg = "--patch-module=$moduleName=${compileJava.get().destinationDirectory.asFile.get().path}"
val testJvmArgs = listOf(
// EnvironmentVariableUtils: make java.util.Map accessible
"--add-opens=java.base/java.util=$moduleName",
// EnvironmentVariableUtils: make java.lang.System accessible
"--add-opens=java.base/java.lang=$moduleName",
patchModuleArg
)
compileTestJava {
options.encoding = "UTF-8"
options.compilerArgs.add("-Werror")
options.compilerArgs.add(patchModuleArg)
var xlintArg = "-Xlint:all"
xlintArg += ",-exports,-requires-automatic"
// missing-explicit-ctor was added in Java 16. This causes errors on test classes, which don't have one.
if (JavaVersion.current() >= JavaVersion.VERSION_16) {
xlintArg += ",-missing-explicit-ctor"
}
options.compilerArgs.add(xlintArg)
}
test {
configure<JacocoTaskExtension> {
isEnabled = !experimentalBuild
}
testLogging {
setExceptionFormat("full")
}
useJUnitPlatform()
filter {
includeTestsMatching("*Tests")
}
// java.security.manager was added in Java 12 (see
// https://www.oracle.com/java/technologies/javase/12-relnote-issues.html#JDK-8191053). We have to explicitly
// set it to "allow" for EnvironmentVariableUtilsTests$With_SecurityManager.
if (JavaVersion.current() >= JavaVersion.VERSION_12)
systemProperty("java.security.manager", "allow")
// Disables Byte Buddy validation for the maximum supported class file version, since we are possibly using a
// Java EA release.
if (experimentalBuild)
systemProperty("net.bytebuddy.experimental", true)
jvmArgs(testJvmArgs)
}
@Suppress("UnstableApiUsage")
testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter()
}
val demoTests by registering(JvmTestSuite::class) {
dependencies {
implementation(project(project.path))
implementation("com.google.jimfs:jimfs:$jimfsVersion")
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("org.assertj:assertj-core:$assertjVersion")
}
sources {
java {
srcDir("src/demo/java")
}
resources {
srcDir("src/demo/resources")
}
}
targets {
all {
testTask.configure {
shouldRunAfter(test)
filter {
includeTestsMatching("*Demo")
}
}
}
}
}
}
}
javadoc {
if (releaseBuild) {
javadocTool.set(project.javaToolchains.javadocToolFor {
// create Javadoc with the minimum Java version needed for our desired features (e.g. search)
languageVersion.set(JavaLanguageVersion.of(23))
})
}
options {
// Cast to standard doclet options, see https://github.com/gradle/gradle/issues/7038#issuecomment-448294937
this as StandardJavadocDocletOptions
encoding = "UTF-8"
links = listOf("https://junit.org/junit5/docs/current/api/")
// Set javadoc `--release` flag (affects which warnings and errors are reported)
// (Note: Gradle adds one leading '-' to the option on its own)
// Have to use at least Java 9 to support modular build
addStringOption("-release", targetJavaVersion.majorVersion.toInt().toString())
// Enable doclint, but ignore warnings for missing tags, see
// https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet
// The Gradle option methods are rather misleading, but a boolean `true` value just makes sure the flag
// is passed to javadoc, see https://github.com/gradle/gradle/issues/2354
addBooleanOption("Xdoclint:all,-missing", true)
}
shouldRunAfter(test)
}
jacocoTestReport {
enabled = !experimentalBuild
reports {
xml.required.set(true)
xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/report.xml"))
}
}
@Suppress("UnstableApiUsage")
check {
// to find Javadoc errors early, let "javadoc" task run during "check"
dependsOn(javadoc, validateYaml, testing.suites.named("demoTests"))
}
withType<Jar>().configureEach {
from(projectDir) {
include("LICENSE.md")
into("META-INF")
}
}
generateChangelog {
dependsOn(":closeAndReleaseSonatypeStagingRepository")
val gitFetchRecentTag = Runtime.getRuntime().exec("git describe --tags --abbrev=0")
val recentTag = gitFetchRecentTag.inputStream.bufferedReader().readText().trim()
previousRevision = recentTag
githubToken = System.getenv("GITHUB_TOKEN")
repository = "junit-pioneer/junit-pioneer"
}
githubRelease {
dependsOn(generateChangelog)
val generateChangelogTask = generateChangelog.get()
repository = generateChangelogTask.repository
changelog = generateChangelogTask.outputFile
githubToken = generateChangelogTask.githubToken
newTagRevision = System.getenv("GITHUB_SHA")
}
}