Skip to content

chore: move common logic into conventional plugin #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ jobs:
with:
gradle-version: wrapper
- name: Build
run: ./gradlew --no-daemon -S -Dorg.gradle.dependency.verification=off -Dorg.gradle.warning.mode=none testClasses
run: >
./gradlew
--no-daemon
-S
-Dorg.gradle.dependency.verification=off
-Dorg.gradle.warning.mode=none
jvmTestClasses
jsTestClasses

# Perform analysis
- name: Perform CodeQL Analysis
Expand Down
3 changes: 1 addition & 2 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
alias(libs.plugins.kotlin.mutliplatform)
convention.kotlin
alias(libs.plugins.kotlin.benchmark)
alias(libs.plugins.kotlin.allopen)
}
Expand All @@ -9,7 +9,6 @@ allOpen {
}

kotlin {
jvmToolchain(11)
jvm()
macosX64()
macosArm64()
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
alias(libs.plugins.kotlin.mutliplatform) apply false
alias(libs.plugins.kotlin.binaryCompatibility)
alias(libs.plugins.nexus.publish)
convention.properties
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ plugins {

repositories {
gradlePluginPortal()
}

dependencies {
implementation(libs.kotlin.gradle.plugin)
}
10 changes: 9 additions & 1 deletion buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
rootProject.name = "buildSrc"
rootProject.name = "buildSrc"

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/convention.kotlin.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
kotlin("multiplatform")
}

kotlin {
jvmToolchain(11)
}
41 changes: 41 additions & 0 deletions buildSrc/src/main/kotlin/convention.mutliplatform-lib.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

plugins {
id("convention.kotlin")
}

kotlin {
explicitApi()

jvm {
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(IR) {
browser()
generateTypeScriptDefinitions()
nodejs()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
// The wasmJsBrowserTest prints all executed tests as one unformatted string
// Have not found a way to suppress printing all this into console
browser()
nodejs()
}

applyDefaultHierarchyTemplate()

macosX64()
macosArm64()
iosX64()
iosArm64()
iosSimulatorArm64()

linuxX64()
linuxArm64()

mingwX64()
}
36 changes: 36 additions & 0 deletions buildSrc/src/main/kotlin/convention.mutliplatform-tests.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests

plugins {
id("convention.kotlin")
}

val macOsAllTest by tasks.register("macOsAllTest") {
group = "verification"
description = "runs all tests for MacOS and IOS targets"
}

val windowsAllTest by tasks.register("windowsAllTest") {
group = "verification"
description = "runs all tests for Windows targets"
}
val linuxAllTest by tasks.register("linuxAllTest") {
group = "verification"
description = "runs all tests for Linux targets"
}

kotlin.targets.configureEach {
if (this !is KotlinTargetWithTests<*, *>) {
return@configureEach
}
when {
name.startsWith("ios") || name.startsWith("macos") -> {
macOsAllTest.dependsOn(tasks.named("${name}Test"))
}
name.startsWith("mingw") -> {
windowsAllTest.dependsOn(tasks.named("${name}Test"))
}
else -> {
linuxAllTest.dependsOn(tasks.named("${name}Test"))
}
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ openapi = "2025.1"
jackson = "2.18.2"

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

[bundles]
openapi = ["openapi-validator", "openapi-interfaces", "openapi-jackson"]
Expand Down
89 changes: 10 additions & 79 deletions json-schema-validator-objects/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

plugins {
alias(libs.plugins.kotlin.mutliplatform)
convention.kotlin
convention.`mutliplatform-lib`
convention.`mutliplatform-tests`
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotest.multiplatform)
alias(libs.plugins.kover)
Expand All @@ -18,51 +18,10 @@ plugins {
}

kotlin {
explicitApi()

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.add("-opt-in=io.github.optimumcode.json.schema.ExperimentalApi")
}
jvmToolchain(11)
jvm {
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(IR) {
browser()
generateTypeScriptDefinitions()
nodejs()
}
wasmJs {
// The wasmJsBrowserTest prints all executed tests as one unformatted string
// Have not found a way to suppress printing all this into console
browser()
nodejs()
}

applyDefaultHierarchyTemplate()

val macOsTargets =
listOf<KotlinTarget>(
macosX64(),
macosArm64(),
iosX64(),
iosArm64(),
iosSimulatorArm64(),
)

val linuxTargets =
listOf<KotlinTarget>(
linuxX64(),
linuxArm64(),
)

val windowsTargets =
listOf<KotlinTarget>(
mingwX64(),
)

sourceSets {
commonMain {
Expand Down Expand Up @@ -101,34 +60,6 @@ kotlin {
}
}
}

afterEvaluate {
fun Task.dependsOnTargetTests(targets: List<KotlinTarget>) {
targets.forEach {
if (it is KotlinTargetWithTests<*, *>) {
dependsOn(tasks.getByName("${it.name}Test"))
}
}
}
tasks.register("macOsAllTest") {
group = "verification"
description = "runs all tests for MacOS and IOS targets"
dependsOnTargetTests(macOsTargets)
}
tasks.register("windowsAllTest") {
group = "verification"
description = "runs all tests for Windows targets"
dependsOnTargetTests(windowsTargets)
}
tasks.register("linuxAllTest") {
group = "verification"
description = "runs all tests for Linux targets"
dependsOnTargetTests(linuxTargets)
dependsOn(tasks.getByName("jvmTest"))
dependsOn(tasks.getByName("jsTest"))
dependsOn(tasks.getByName("wasmJsTest"))
}
}
}

ktlint {
Expand All @@ -138,12 +69,12 @@ ktlint {
}
}

afterEvaluate {
val detektAllTask by tasks.register("detektAll") {
dependsOn(tasks.withType<Detekt>())
}
val detektAllTask by tasks.register("detektAll")

tasks.named("check").configure {
dependsOn(detektAllTask)
}
tasks.named("check").configure {
dependsOn(detektAllTask)
}

tasks.withType<Detekt> {
detektAllTask.dependsOn(this)
}
Loading
Loading