Skip to content

Commit 94e40c2

Browse files
committed
Rewrite buildscript to utilize test suites
1 parent 5061bc0 commit 94e40c2

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

build.gradle.kts

+44-49
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,48 @@ repositories {
2323
mavenCentral()
2424
}
2525

26-
sourceSets {
27-
val main = main.get()
28-
val dev = create("dev") {
29-
compileClasspath += main.output
30-
runtimeClasspath += main.output
31-
}
32-
test {
33-
compileClasspath += dev.output
34-
runtimeClasspath += dev.output
35-
}
36-
create("testIntegration") {
37-
compileClasspath += main.output + test.get().output + dev.output
38-
runtimeClasspath += main.output + test.get().output + dev.output
26+
val devSourceSet = sourceSets.create("dev") {
27+
val main = sourceSets.main.get()
28+
compileClasspath += main.output
29+
runtimeClasspath += main.output
30+
}
31+
32+
lateinit var testIntegration: NamedDomainObjectProvider<JvmTestSuite>
33+
testing {
34+
suites {
35+
val test by getting(JvmTestSuite::class)
36+
testIntegration = register<JvmTestSuite>("testIntegration") {
37+
dependencies {
38+
implementation(project())
39+
implementation(sourceSets.test.get().output)
40+
}
41+
targets {
42+
all {
43+
testTask.configure {
44+
shouldRunAfter(test)
45+
}
46+
}
47+
}
48+
}
49+
withType<JvmTestSuite> {
50+
useJUnitJupiter()
51+
52+
dependencies {
53+
// testing
54+
implementation(tests.junit.api)
55+
runtimeOnly(tests.junit.engine)
56+
runtimeOnly(tests.junit.launcher)
57+
implementation(tests.ktor.server.tests)
58+
implementation(tests.mockk)
59+
implementation(tests.assertj.core)
60+
implementation(tests.json)
61+
implementation(tests.h2)
62+
implementation(tests.testcontainers)
63+
implementation(tests.testcontainers.junit)
64+
implementation(tests.testcontainers.keycloak)
65+
implementation(devSourceSet.output)
66+
}
67+
}
3968
}
4069
}
4170

@@ -99,19 +128,6 @@ dependencies {
99128
// task scheduling
100129
implementation(libraries.jobrunr)
101130

102-
// testing
103-
testImplementation(tests.junit.api)
104-
testRuntimeOnly(tests.junit.engine)
105-
testRuntimeOnly(tests.junit.launcher)
106-
testImplementation(tests.ktor.server.tests)
107-
testImplementation(tests.mockk)
108-
testImplementation(tests.assertj.core)
109-
testImplementation(tests.json)
110-
testImplementation(tests.h2)
111-
testImplementation(tests.testcontainers)
112-
testImplementation(tests.testcontainers.junit)
113-
testImplementation(tests.testcontainers.keycloak)
114-
115131
// dev
116132
devImplementation(dev.keycloak.adminClient)
117133
}
@@ -122,36 +138,17 @@ application {
122138
if (isDevelopment) {
123139
applicationDefaultJvmArgs += "-Dio.ktor.development=$isDevelopment"
124140
tasks.run.configure {
125-
classpath += sourceSets["dev"].output
141+
classpath += devSourceSet.output
126142
}
127143
}
128144
}
129145

130146
tasks.test {
131147
jvmArgs("-Dio.ktor.development=true")
132-
useJUnitPlatform()
133-
}
134-
135-
val integrationTest: SourceSet = sourceSets["testIntegration"]
136-
137-
138-
configurations[integrationTest.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())
139-
configurations[integrationTest.runtimeOnlyConfigurationName].extendsFrom(configurations.testRuntimeOnly.get())
140-
141-
val integrationTestTask = tasks.register<Test>("integrationTest") {
142-
group = "verification"
143-
description = "Runs tests against integrations (database, LMS, etc)"
144-
145-
useJUnitPlatform()
146-
147-
testClassesDirs = integrationTest.output.classesDirs
148-
classpath = integrationTest.runtimeClasspath
149-
150-
shouldRunAfter("test")
151148
}
152149

153150
tasks.check {
154-
dependsOn(integrationTestTask)
151+
dependsOn(testIntegration)
155152
}
156153

157154
buildInfo {
@@ -229,8 +226,6 @@ idea {
229226
// long import times but worth it as, without it, functions may not have proper documentation
230227
isDownloadJavadoc = true
231228
isDownloadSources = true
232-
sourceDirs.minusAssign(file("src/testIntegration"))
233-
testSources.from(file("src/testIntegration/kotlin"))
234229
}
235230

236231
project {

0 commit comments

Comments
 (0)