Skip to content

Commit 9750aae

Browse files
authored
Apply jvm test suite plugin to register custom sourceset
Signed-off-by: Taeik Lim <[email protected]>
1 parent db4d7b2 commit 9750aae

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

buildSrc/src/main/kotlin/spring.batch.plus.java-library-conventions.gradle.kts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ plugins {
33
// https://docs.gradle.org/current/userguide/java_library_plugin.html
44
`java-library`
55

6+
// for managing custom test suite
7+
// https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html
8+
`jvm-test-suite`
9+
610
// coverage, jacoco can cover kotlin codes
711
// https://docs.gradle.org/current/userguide/jacoco_plugin.html
812
jacoco
@@ -48,35 +52,50 @@ tasks.javadoc {
4852
}
4953
}
5054

51-
tasks.named<Test>("test") {
52-
useJUnitPlatform()
53-
maxParallelForks = Runtime.getRuntime().availableProcessors()
54-
}
55-
56-
sourceSets {
57-
create("integrationTest") {
58-
compileClasspath += sourceSets.main.get().output
59-
runtimeClasspath += sourceSets.main.get().output
55+
testing {
56+
suites {
57+
// reference to test task which is automatically created
58+
val test by getting(JvmTestSuite::class) {
59+
targets {
60+
all {
61+
testTask.configure {
62+
useJUnitPlatform()
63+
maxParallelForks = Runtime.getRuntime().availableProcessors()
64+
}
65+
}
66+
}
67+
}
68+
69+
register<JvmTestSuite>("integrationTest") {
70+
dependencies {
71+
// add dependency of project itself
72+
implementation(project())
73+
}
74+
75+
targets {
76+
all {
77+
testTask.configure {
78+
// run after 'test' task
79+
shouldRunAfter(test)
80+
81+
useJUnitPlatform()
82+
maxParallelForks = Runtime.getRuntime().availableProcessors()
83+
}
84+
}
85+
}
86+
}
6087
}
6188
}
89+
90+
// configure dependencies integrationTest from project itself
91+
// see also: https://github.com/gradle/gradle/issues/19870
6292
val integrationTestImplementation: Configuration by configurations.getting {
6393
extendsFrom(configurations.implementation.get(), configurations.testImplementation.get())
6494
}
6595
val integrationTestRuntimeOnly: Configuration by configurations.getting {
6696
extendsFrom(configurations.runtimeOnly.get(), configurations.testRuntimeOnly.get())
6797
}
6898

69-
tasks.register<Test>("integrationTest") {
70-
// run after 'test' task
71-
shouldRunAfter("test")
72-
73-
useJUnitPlatform()
74-
maxParallelForks = Runtime.getRuntime().availableProcessors()
75-
76-
testClassesDirs = sourceSets["integrationTest"].output.classesDirs
77-
classpath = sourceSets["integrationTest"].runtimeClasspath
78-
}
79-
8099

81100
/* jacoco */
82101

0 commit comments

Comments
 (0)