diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8742c6ea..3c451766 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -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 diff --git a/benchmark/build.gradle.kts b/benchmark/build.gradle.kts index d083493f..c105be50 100644 --- a/benchmark/build.gradle.kts +++ b/benchmark/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - alias(libs.plugins.kotlin.mutliplatform) + convention.kotlin alias(libs.plugins.kotlin.benchmark) alias(libs.plugins.kotlin.allopen) } @@ -9,7 +9,6 @@ allOpen { } kotlin { - jvmToolchain(11) jvm() macosX64() macosArm64() diff --git a/build.gradle.kts b/build.gradle.kts index f0308b58..5060e5f4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,4 @@ plugins { - alias(libs.plugins.kotlin.mutliplatform) apply false alias(libs.plugins.kotlin.binaryCompatibility) alias(libs.plugins.nexus.publish) convention.properties diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 25ba73db..cedccb31 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -4,4 +4,8 @@ plugins { repositories { gradlePluginPortal() +} + +dependencies { + implementation(libs.kotlin.gradle.plugin) } \ No newline at end of file diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 3f87d39f..d754ac31 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1 +1,9 @@ -rootProject.name = "buildSrc" \ No newline at end of file +rootProject.name = "buildSrc" + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/convention.kotlin.gradle.kts b/buildSrc/src/main/kotlin/convention.kotlin.gradle.kts new file mode 100644 index 00000000..66f0a62c --- /dev/null +++ b/buildSrc/src/main/kotlin/convention.kotlin.gradle.kts @@ -0,0 +1,7 @@ +plugins { + kotlin("multiplatform") +} + +kotlin { + jvmToolchain(11) +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/convention.mutliplatform-lib.gradle.kts b/buildSrc/src/main/kotlin/convention.mutliplatform-lib.gradle.kts new file mode 100644 index 00000000..e2cf29a9 --- /dev/null +++ b/buildSrc/src/main/kotlin/convention.mutliplatform-lib.gradle.kts @@ -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() +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/convention.mutliplatform-tests.gradle.kts b/buildSrc/src/main/kotlin/convention.mutliplatform-tests.gradle.kts new file mode 100644 index 00000000..3970a6bb --- /dev/null +++ b/buildSrc/src/main/kotlin/convention.mutliplatform-tests.gradle.kts @@ -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")) + } + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b340ac5c..3aee5358 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } @@ -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"] diff --git a/json-schema-validator-objects/build.gradle.kts b/json-schema-validator-objects/build.gradle.kts index d352d7fe..5b895fbb 100644 --- a/json-schema-validator-objects/build.gradle.kts +++ b/json-schema-validator-objects/build.gradle.kts @@ -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) @@ -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( - macosX64(), - macosArm64(), - iosX64(), - iosArm64(), - iosSimulatorArm64(), - ) - - val linuxTargets = - listOf( - linuxX64(), - linuxArm64(), - ) - - val windowsTargets = - listOf( - mingwX64(), - ) sourceSets { commonMain { @@ -101,34 +60,6 @@ kotlin { } } } - - afterEvaluate { - fun Task.dependsOnTargetTests(targets: List) { - 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 { @@ -138,12 +69,12 @@ ktlint { } } -afterEvaluate { - val detektAllTask by tasks.register("detektAll") { - dependsOn(tasks.withType()) - } +val detektAllTask by tasks.register("detektAll") - tasks.named("check").configure { - dependsOn(detektAllTask) - } +tasks.named("check").configure { + dependsOn(detektAllTask) +} + +tasks.withType { + detektAllTask.dependsOn(this) } \ No newline at end of file diff --git a/json-schema-validator/build.gradle.kts b/json-schema-validator/build.gradle.kts index 339f4824..bff57a4f 100644 --- a/json-schema-validator/build.gradle.kts +++ b/json-schema-validator/build.gradle.kts @@ -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) @@ -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( - macosX64(), - macosArm64(), - iosX64(), - iosArm64(), - iosSimulatorArm64(), - ) - - val linuxTargets = - listOf( - linuxX64(), - linuxArm64(), - ) - - val windowsTargets = - listOf( - mingwX64(), - ) sourceSets { val commonMain by getting { @@ -115,34 +74,6 @@ kotlin { } } } - - afterEvaluate { - fun Task.dependsOnTargetTests(targets: List) { - 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 { @@ -152,12 +83,12 @@ ktlint { } } -afterEvaluate { - val detektAllTask by tasks.register("detektAll") { - dependsOn(tasks.withType()) - } +val detektAllTask by tasks.register("detektAll") - tasks.named("check").configure { - dependsOn(detektAllTask) - } +tasks.named("check").configure { + dependsOn(detektAllTask) +} + +tasks.withType { + detektAllTask.dependsOn(this) } \ No newline at end of file diff --git a/test-suites/build.gradle.kts b/test-suites/build.gradle.kts index b81a624c..161e74d8 100644 --- a/test-suites/build.gradle.kts +++ b/test-suites/build.gradle.kts @@ -1,13 +1,12 @@ import io.gitlab.arturbosch.detekt.Detekt -import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest import org.jlleitschuh.gradle.ktlint.reporter.ReporterType plugins { - alias(libs.plugins.kotlin.mutliplatform) + convention.kotlin + convention.`mutliplatform-tests` alias(libs.plugins.kotlin.serialization) alias(libs.plugins.kotest.multiplatform) alias(libs.plugins.kover) @@ -17,9 +16,8 @@ plugins { kotlin { explicitApi() - jvmToolchain(11) + jvm { - withJava() testRuns["test"].executionTask.configure { useJUnitPlatform() } @@ -30,25 +28,16 @@ kotlin { // wasmJs target is not added because the okio does not provide a dependency to use FileSystem API in wasmJs target applyDefaultHierarchyTemplate() - val macOsTargets = - listOf( - macosX64(), - macosArm64(), - iosX64(), - iosArm64(), - iosSimulatorArm64(), - ) - - val linuxTargets = - listOf( - linuxX64(), - linuxArm64(), - ) - - val windowsTargets = - listOf( - mingwX64(), - ) + macosX64() + macosArm64() + iosX64() + iosArm64() + iosSimulatorArm64() + + linuxX64() + linuxArm64() + + mingwX64() sourceSets { commonTest { @@ -73,33 +62,6 @@ kotlin { } } } - - afterEvaluate { - fun Task.dependsOnTargetTests(targets: List) { - 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")) - } - } } dependencies { @@ -161,12 +123,12 @@ ktlint { } } -afterEvaluate { - val detektAllTask by tasks.register("detektAll") { - dependsOn(tasks.withType()) - } +val detektAllTask by tasks.register("detektAll") - tasks.named("check").configure { - dependsOn(detektAllTask) - } +tasks.named("check").configure { + dependsOn(detektAllTask) +} + +tasks.withType { + detektAllTask.dependsOn(this) } \ No newline at end of file