Skip to content

Commit 1082f55

Browse files
authored
chore: move common logic into conventional plugin (#267)
Resolves #266
1 parent 34ba3ba commit 1082f55

File tree

12 files changed

+147
-222
lines changed

12 files changed

+147
-222
lines changed

.github/workflows/codeql.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ jobs:
5353
with:
5454
gradle-version: wrapper
5555
- name: Build
56-
run: ./gradlew --no-daemon -S -Dorg.gradle.dependency.verification=off -Dorg.gradle.warning.mode=none testClasses
56+
run: >
57+
./gradlew
58+
--no-daemon
59+
-S
60+
-Dorg.gradle.dependency.verification=off
61+
-Dorg.gradle.warning.mode=none
62+
jvmTestClasses
63+
jsTestClasses
5764
5865
# Perform analysis
5966
- name: Perform CodeQL Analysis

benchmark/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
alias(libs.plugins.kotlin.mutliplatform)
2+
convention.kotlin
33
alias(libs.plugins.kotlin.benchmark)
44
alias(libs.plugins.kotlin.allopen)
55
}
@@ -9,7 +9,6 @@ allOpen {
99
}
1010

1111
kotlin {
12-
jvmToolchain(11)
1312
jvm()
1413
macosX64()
1514
macosArm64()

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
plugins {
2-
alias(libs.plugins.kotlin.mutliplatform) apply false
32
alias(libs.plugins.kotlin.binaryCompatibility)
43
alias(libs.plugins.nexus.publish)
54
convention.properties

buildSrc/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ plugins {
44

55
repositories {
66
gradlePluginPortal()
7+
}
8+
9+
dependencies {
10+
implementation(libs.kotlin.gradle.plugin)
711
}

buildSrc/settings.gradle.kts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
rootProject.name = "buildSrc"
1+
rootProject.name = "buildSrc"
2+
3+
dependencyResolutionManagement {
4+
versionCatalogs {
5+
create("libs") {
6+
from(files("../gradle/libs.versions.toml"))
7+
}
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
kotlin("multiplatform")
3+
}
4+
5+
kotlin {
6+
jvmToolchain(11)
7+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
2+
3+
plugins {
4+
id("convention.kotlin")
5+
}
6+
7+
kotlin {
8+
explicitApi()
9+
10+
jvm {
11+
testRuns["test"].executionTask.configure {
12+
useJUnitPlatform()
13+
}
14+
}
15+
js(IR) {
16+
browser()
17+
generateTypeScriptDefinitions()
18+
nodejs()
19+
}
20+
21+
@OptIn(ExperimentalWasmDsl::class)
22+
wasmJs {
23+
// The wasmJsBrowserTest prints all executed tests as one unformatted string
24+
// Have not found a way to suppress printing all this into console
25+
browser()
26+
nodejs()
27+
}
28+
29+
applyDefaultHierarchyTemplate()
30+
31+
macosX64()
32+
macosArm64()
33+
iosX64()
34+
iosArm64()
35+
iosSimulatorArm64()
36+
37+
linuxX64()
38+
linuxArm64()
39+
40+
mingwX64()
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
2+
3+
plugins {
4+
id("convention.kotlin")
5+
}
6+
7+
val macOsAllTest by tasks.register("macOsAllTest") {
8+
group = "verification"
9+
description = "runs all tests for MacOS and IOS targets"
10+
}
11+
12+
val windowsAllTest by tasks.register("windowsAllTest") {
13+
group = "verification"
14+
description = "runs all tests for Windows targets"
15+
}
16+
val linuxAllTest by tasks.register("linuxAllTest") {
17+
group = "verification"
18+
description = "runs all tests for Linux targets"
19+
}
20+
21+
kotlin.targets.configureEach {
22+
if (this !is KotlinTargetWithTests<*, *>) {
23+
return@configureEach
24+
}
25+
when {
26+
name.startsWith("ios") || name.startsWith("macos") -> {
27+
macOsAllTest.dependsOn(tasks.named("${name}Test"))
28+
}
29+
name.startsWith("mingw") -> {
30+
windowsAllTest.dependsOn(tasks.named("${name}Test"))
31+
}
32+
else -> {
33+
linuxAllTest.dependsOn(tasks.named("${name}Test"))
34+
}
35+
}
36+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ openapi = "2025.1"
1010
jackson = "2.18.2"
1111

1212
[plugins]
13-
kotlin-mutliplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
1413
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
1514
kotlin-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "benchmark" }
1615
kotlin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }
@@ -42,6 +41,7 @@ networknt-validator = { group = "com.networknt", name = "json-schema-validator",
4241
kotlin-codepoints = { group = "de.cketti.unicode", name = "kotlin-codepoints", version = "0.9.0" }
4342
normalize = { group = "com.doist.x", name = "normalize", version = "1.1.1" }
4443
karacteristics = { group = "io.github.optimumcode", name = "karacteristics", version = "0.0.4" }
44+
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
4545

4646
[bundles]
4747
openapi = ["openapi-validator", "openapi-interfaces", "openapi-jackson"]

json-schema-validator-objects/build.gradle.kts

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import io.gitlab.arturbosch.detekt.Detekt
44
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
55
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
6-
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
7-
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
86
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
97

108
plugins {
11-
alias(libs.plugins.kotlin.mutliplatform)
9+
convention.kotlin
10+
convention.`mutliplatform-lib`
11+
convention.`mutliplatform-tests`
1212
alias(libs.plugins.kotlin.serialization)
1313
alias(libs.plugins.kotest.multiplatform)
1414
alias(libs.plugins.kover)
@@ -18,51 +18,10 @@ plugins {
1818
}
1919

2020
kotlin {
21-
explicitApi()
22-
2321
@OptIn(ExperimentalKotlinGradlePluginApi::class)
2422
compilerOptions {
2523
freeCompilerArgs.add("-opt-in=io.github.optimumcode.json.schema.ExperimentalApi")
2624
}
27-
jvmToolchain(11)
28-
jvm {
29-
testRuns["test"].executionTask.configure {
30-
useJUnitPlatform()
31-
}
32-
}
33-
js(IR) {
34-
browser()
35-
generateTypeScriptDefinitions()
36-
nodejs()
37-
}
38-
wasmJs {
39-
// The wasmJsBrowserTest prints all executed tests as one unformatted string
40-
// Have not found a way to suppress printing all this into console
41-
browser()
42-
nodejs()
43-
}
44-
45-
applyDefaultHierarchyTemplate()
46-
47-
val macOsTargets =
48-
listOf<KotlinTarget>(
49-
macosX64(),
50-
macosArm64(),
51-
iosX64(),
52-
iosArm64(),
53-
iosSimulatorArm64(),
54-
)
55-
56-
val linuxTargets =
57-
listOf<KotlinTarget>(
58-
linuxX64(),
59-
linuxArm64(),
60-
)
61-
62-
val windowsTargets =
63-
listOf<KotlinTarget>(
64-
mingwX64(),
65-
)
6625

6726
sourceSets {
6827
commonMain {
@@ -101,34 +60,6 @@ kotlin {
10160
}
10261
}
10362
}
104-
105-
afterEvaluate {
106-
fun Task.dependsOnTargetTests(targets: List<KotlinTarget>) {
107-
targets.forEach {
108-
if (it is KotlinTargetWithTests<*, *>) {
109-
dependsOn(tasks.getByName("${it.name}Test"))
110-
}
111-
}
112-
}
113-
tasks.register("macOsAllTest") {
114-
group = "verification"
115-
description = "runs all tests for MacOS and IOS targets"
116-
dependsOnTargetTests(macOsTargets)
117-
}
118-
tasks.register("windowsAllTest") {
119-
group = "verification"
120-
description = "runs all tests for Windows targets"
121-
dependsOnTargetTests(windowsTargets)
122-
}
123-
tasks.register("linuxAllTest") {
124-
group = "verification"
125-
description = "runs all tests for Linux targets"
126-
dependsOnTargetTests(linuxTargets)
127-
dependsOn(tasks.getByName("jvmTest"))
128-
dependsOn(tasks.getByName("jsTest"))
129-
dependsOn(tasks.getByName("wasmJsTest"))
130-
}
131-
}
13263
}
13364

13465
ktlint {
@@ -138,12 +69,12 @@ ktlint {
13869
}
13970
}
14071

141-
afterEvaluate {
142-
val detektAllTask by tasks.register("detektAll") {
143-
dependsOn(tasks.withType<Detekt>())
144-
}
72+
val detektAllTask by tasks.register("detektAll")
14573

146-
tasks.named("check").configure {
147-
dependsOn(detektAllTask)
148-
}
74+
tasks.named("check").configure {
75+
dependsOn(detektAllTask)
76+
}
77+
78+
tasks.withType<Detekt> {
79+
detektAllTask.dependsOn(this)
14980
}

0 commit comments

Comments
 (0)