Skip to content

Commit 456f769

Browse files
authored
Extract test suite setup to plugin (#179)
`:library` build logic became convoluted. Splitting it into discrete convention plugins improves maintainability. Create a `build-logic` project and extract test suite setup to it as a precompiled script plugin.
1 parent 72f75f3 commit 456f769

File tree

7 files changed

+74
-48
lines changed

7 files changed

+74
-48
lines changed

build-logic/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@file:Suppress("UnstableApiUsage")
2+
3+
plugins {
4+
`kotlin-dsl`
5+
}
6+
7+
dependencies {
8+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
9+
}

build-logic/settings.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@file:Suppress("UnstableApiUsage")
2+
3+
dependencyResolutionManagement {
4+
repositories {
5+
mavenCentral()
6+
gradlePluginPortal()
7+
}
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.gabrielfeo
2+
3+
plugins {
4+
id("org.jetbrains.kotlin.jvm")
5+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.gabrielfeo
2+
3+
plugins {
4+
id("org.jetbrains.kotlin.jvm")
5+
`java-test-fixtures`
6+
}
7+
8+
testing {
9+
suites {
10+
// 'test' is registered by default
11+
register<JvmTestSuite>("integrationTest")
12+
withType<JvmTestSuite>().configureEach {
13+
useKotlinTest()
14+
}
15+
}
16+
}
17+
18+
tasks.named("check") {
19+
dependsOn("integrationTest")
20+
}
21+
22+
kotlin {
23+
target {
24+
val main by compilations.getting
25+
val integrationTest by compilations.getting
26+
val test by compilations.getting
27+
val testFixtures by compilations.getting
28+
test.associateWith(main)
29+
test.associateWith(testFixtures)
30+
integrationTest.associateWith(main)
31+
integrationTest.associateWith(testFixtures)
32+
testFixtures.associateWith(main)
33+
}
34+
}
35+
36+
// TODO Unapply test-fixtures and delete the source set, since we're not publishing it?
37+
components.getByName<AdhocComponentWithVariants>("java").apply {
38+
withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
39+
withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
40+
}

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
plugins {
2-
id("org.jetbrains.kotlin.jvm") version "1.9.23" apply false
32
id("org.jetbrains.dokka") version "1.9.20" apply false
43
id("org.openapi.generator") version "7.3.0" apply false
54
}

library/build.gradle.kts

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import org.jetbrains.dokka.DokkaConfiguration.Visibility.PUBLIC
55
import org.jetbrains.dokka.gradle.DokkaTask
66

77
plugins {
8-
id("org.jetbrains.kotlin.jvm")
8+
id("com.gabrielfeo.kotlin-jvm-library")
9+
id("com.gabrielfeo.test-suites")
910
id("org.jetbrains.dokka")
1011
id("org.openapi.generator")
1112
`java-library`
12-
`java-test-fixtures`
1313
`maven-publish`
14-
`signing`
14+
signing
1515
}
1616

1717
val repoUrl = "https://github.com/gabrielfeo/gradle-enterprise-api-kotlin"
@@ -158,11 +158,6 @@ java {
158158
}
159159
}
160160

161-
components.getByName<AdhocComponentWithVariants>("java").apply {
162-
withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
163-
withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
164-
}
165-
166161
tasks.withType<DokkaTask>().configureEach {
167162
dokkaSourceSets.all {
168163
sourceLink {
@@ -189,45 +184,6 @@ tasks.named<Jar>("javadocJar") {
189184
from(tasks.dokkaHtml)
190185
}
191186

192-
testing {
193-
suites {
194-
getByName<JvmTestSuite>("test") {
195-
dependencies {
196-
implementation("com.squareup.okhttp3:mockwebserver:4.12.0")
197-
implementation("com.squareup.okio:okio:3.9.0")
198-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0")
199-
}
200-
}
201-
register<JvmTestSuite>("integrationTest") {
202-
dependencies {
203-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0")
204-
implementation("com.google.guava:guava:33.1.0-jre")
205-
}
206-
}
207-
withType<JvmTestSuite>().configureEach {
208-
useKotlinTest()
209-
}
210-
}
211-
}
212-
213-
kotlin {
214-
target {
215-
val main by compilations.getting
216-
val integrationTest by compilations.getting
217-
val test by compilations.getting
218-
val testFixtures by compilations.getting
219-
test.associateWith(main)
220-
test.associateWith(testFixtures)
221-
integrationTest.associateWith(main)
222-
integrationTest.associateWith(testFixtures)
223-
testFixtures.associateWith(main)
224-
}
225-
}
226-
227-
tasks.named("check") {
228-
dependsOn("integrationTest")
229-
}
230-
231187
tasks.named<Test>("integrationTest") {
232188
jvmArgs("-Xmx512m")
233189
environment("GRADLE_ENTERPRISE_API_LOG_LEVEL", "DEBUG")
@@ -253,6 +209,11 @@ dependencies {
253209
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
254210
implementation("org.slf4j:slf4j-api:2.0.11")
255211
implementation("ch.qos.logback:logback-classic:1.4.14")
212+
testImplementation("com.squareup.okhttp3:mockwebserver:4.12.0")
213+
testImplementation("com.squareup.okio:okio:3.9.0")
214+
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0")
215+
integrationTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0")
216+
integrationTestImplementation("com.google.guava:guava:33.1.0-jre")
256217
}
257218

258219
publishing {

settings.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
pluginManagement {
2+
includeBuild("./build-logic")
3+
}
4+
15
plugins {
26
id("com.gradle.enterprise") version("3.13.2")
37
id("org.gradle.toolchains.foojay-resolver-convention") version("0.4.0")

0 commit comments

Comments
 (0)