From 373906e1562b7e6078595781ce0988b89f8f2d5b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Apr 2025 14:39:12 +0600 Subject: [PATCH] rework templates --- gradle/libs.versions.toml | 5 +- .../templates/defaultAndroidSettings.gradle | 8 +-- gradle/templates/defaultProject.gradle | 24 +++++++ .../defaultProjectWithSerialization.gradle | 25 +++++++ gradle/templates/enableMPPAndroid.gradle | 31 ++++++++ gradle/templates/enableMPPJs.gradle | 30 ++++++++ gradle/templates/enableMPPJvm.gradle | 21 ++++++ gradle/templates/enableMPPNativeArm64.gradle | 8 +++ gradle/templates/enableMPPNativeX64.gradle | 10 +++ gradle/templates/enableMPPWasmJs.gradle | 27 +++++++ gradle/templates/mppAndroidProject.gradle | 44 ++---------- gradle/templates/mppJavaProject.gradle | 41 +---------- gradle/templates/mppJsProject.gradle | 33 +-------- .../mppProjectWithSerialization.gradle | 70 ++----------------- gradle/wrapper/gradle-wrapper.properties | 2 +- 15 files changed, 196 insertions(+), 183 deletions(-) create mode 100644 gradle/templates/defaultProject.gradle create mode 100644 gradle/templates/defaultProjectWithSerialization.gradle create mode 100644 gradle/templates/enableMPPAndroid.gradle create mode 100644 gradle/templates/enableMPPJs.gradle create mode 100644 gradle/templates/enableMPPJvm.gradle create mode 100644 gradle/templates/enableMPPNativeArm64.gradle create mode 100644 gradle/templates/enableMPPNativeX64.gradle create mode 100644 gradle/templates/enableMPPWasmJs.gradle diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9d9c21d..7020ea0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,6 +2,7 @@ kotlin = "2.1.20" kotlin-serialization = "1.8.1" +kotlin-coroutines = "1.10.2" dokka = "2.0.0" @@ -19,12 +20,14 @@ android-buildTools = "35.0.0" kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlin-serialization" } +kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" } +kotlin-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlin-coroutines" } kotlin-test-common = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlin" } kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" } kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } kotlin-test-js = { module = "org.jetbrains.kotlin:kotlin-test-js", version.ref = "kotlin" } android-test-junit = { module = "androidx.test.ext:junit", version.ref = "test_ext_junit_version" } -android-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso_core" } +android-test-espresso = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso_core" } # buildscript classpaths diff --git a/gradle/templates/defaultAndroidSettings.gradle b/gradle/templates/defaultAndroidSettings.gradle index c47f89c..2cda03f 100644 --- a/gradle/templates/defaultAndroidSettings.gradle +++ b/gradle/templates/defaultAndroidSettings.gradle @@ -4,14 +4,13 @@ android { compileSdkVersion libs.versions.android.compileSdk.get().toInteger() buildToolsVersion libs.versions.android.buildTools.get() - namespace "${group}.${project.name}" - defaultConfig { minSdkVersion libs.versions.android.minSdk.get().toInteger() compileSdkVersion libs.versions.android.compileSdk.get().toInteger() targetSdkVersion libs.versions.android.compileSdk.get().toInteger() versionCode "${android_code_version}".toInteger() versionName "$version" + namespace "${project.group}.${project.name}" } buildTypes { release { @@ -32,9 +31,4 @@ android { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } - - sourceSets { - String sep = File.separator - main.java.srcDirs += "src${sep}main${sep}kotlin" - } } diff --git a/gradle/templates/defaultProject.gradle b/gradle/templates/defaultProject.gradle new file mode 100644 index 0000000..4282c3c --- /dev/null +++ b/gradle/templates/defaultProject.gradle @@ -0,0 +1,24 @@ +project.version = "$version" +project.group = "$group" + +kotlin { + sourceSets { + commonMain { + dependencies { + implementation kotlin('stdlib') + } + } + commonTest { + dependencies { + implementation kotlin('test-common') + implementation kotlin('test-annotations-common') + implementation libs.kotlin.coroutines.test + } + } + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} diff --git a/gradle/templates/defaultProjectWithSerialization.gradle b/gradle/templates/defaultProjectWithSerialization.gradle new file mode 100644 index 0000000..d7f3924 --- /dev/null +++ b/gradle/templates/defaultProjectWithSerialization.gradle @@ -0,0 +1,25 @@ +project.version = "$version" +project.group = "$group" + +kotlin { + sourceSets { + commonMain { + dependencies { + implementation kotlin('stdlib') + api libs.kotlin.serialization + } + } + commonTest { + dependencies { + implementation kotlin('test-common') + implementation kotlin('test-annotations-common') + implementation libs.kotlin.coroutines.test + } + } + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} diff --git a/gradle/templates/enableMPPAndroid.gradle b/gradle/templates/enableMPPAndroid.gradle new file mode 100644 index 0000000..1c635db --- /dev/null +++ b/gradle/templates/enableMPPAndroid.gradle @@ -0,0 +1,31 @@ +kotlin { + androidTarget { + publishAllLibraryVariants() + compilations.all { + kotlinOptions { + jvmTarget = "17" + } + } + } + + sourceSets { + androidUnitTest { + dependencies { + implementation kotlin('test-junit') + implementation libs.android.test.junit + implementation libs.android.test.espresso + } + } + androidInstrumentedTest { + dependencies { + implementation kotlin('test-junit') + implementation libs.android.test.junit + implementation libs.android.test.espresso + } + } + + androidMain.dependsOn jvmMain + } +} + +apply from: "$defaultAndroidSettings" diff --git a/gradle/templates/enableMPPJs.gradle b/gradle/templates/enableMPPJs.gradle new file mode 100644 index 0000000..e376278 --- /dev/null +++ b/gradle/templates/enableMPPJs.gradle @@ -0,0 +1,30 @@ +kotlin { + js (IR) { + browser { + testTask { + useMocha { + timeout = "240000" + } + } + } + nodejs { + testTask { + useMocha { + timeout = "240000" + } + } + } + } + + sourceSets { + jsMain { + dependencies { + } + } + jsTest { + dependencies { + implementation kotlin('test-js') + } + } + } +} diff --git a/gradle/templates/enableMPPJvm.gradle b/gradle/templates/enableMPPJvm.gradle new file mode 100644 index 0000000..28abd02 --- /dev/null +++ b/gradle/templates/enableMPPJvm.gradle @@ -0,0 +1,21 @@ +kotlin { + jvm { + compilations.main { + kotlinOptions { + jvmTarget = "17" + } + } + } + + sourceSets { + jvmMain { + dependencies { + } + } + jvmTest { + dependencies { + implementation kotlin('test-junit') + } + } + } +} diff --git a/gradle/templates/enableMPPNativeArm64.gradle b/gradle/templates/enableMPPNativeArm64.gradle new file mode 100644 index 0000000..191519d --- /dev/null +++ b/gradle/templates/enableMPPNativeArm64.gradle @@ -0,0 +1,8 @@ +kotlin { + linuxArm64() + + sourceSets { + nativeMain.dependsOn commonMain + linuxArm64Main.dependsOn nativeMain + } +} diff --git a/gradle/templates/enableMPPNativeX64.gradle b/gradle/templates/enableMPPNativeX64.gradle new file mode 100644 index 0000000..e656b94 --- /dev/null +++ b/gradle/templates/enableMPPNativeX64.gradle @@ -0,0 +1,10 @@ +kotlin { + linuxX64() + mingwX64() + + sourceSets { + nativeMain.dependsOn commonMain + linuxX64Main.dependsOn nativeMain + mingwX64Main.dependsOn nativeMain + } +} diff --git a/gradle/templates/enableMPPWasmJs.gradle b/gradle/templates/enableMPPWasmJs.gradle new file mode 100644 index 0000000..d670f42 --- /dev/null +++ b/gradle/templates/enableMPPWasmJs.gradle @@ -0,0 +1,27 @@ +kotlin { + wasmJs { + browser { + testTask { + useKarma { + useChromeHeadless() + useConfigDirectory(rootProject.relativeProjectPath("gradle/karma.config.d")) + } + } + } + nodejs { + testTask { + timeout = Duration.ofSeconds(240) + nodeJsArgs.add("--unhandled-rejections=warn") + nodeJsArgs.add("--trace-warnings") + } + } + } + + sourceSets { + wasmJsTest { + dependencies { + implementation kotlin('test-wasm-js') + } + } + } +} diff --git a/gradle/templates/mppAndroidProject.gradle b/gradle/templates/mppAndroidProject.gradle index f541758..cb6f0bc 100644 --- a/gradle/templates/mppAndroidProject.gradle +++ b/gradle/templates/mppAndroidProject.gradle @@ -1,39 +1,5 @@ -project.version = "$version" -project.group = "$group" - -// apply from: "$publishGradlePath" - -kotlin { - androidTarget { - publishAllLibraryVariants() - compilations.all { - kotlinOptions { - jvmTarget = "17" - } - } - } - - sourceSets { - commonMain { - dependencies { - implementation libs.kotlin - api libs.kotlin.serialization - } - } - commonTest { - dependencies { - implementation libs.kotlin.test.common - implementation libs.kotlin.test.annotations.common - } - } - androidUnitTest { - dependencies { - implementation libs.kotlin.test.junit - implementation libs.android.test.junit - implementation libs.android.test.espresso.core - } - } - } -} - -apply from: "$defaultAndroidSettings" +apply from: "$defaultProject" +apply from: "$enableMPPJvm" +apply from: "$enableMPPJs" +apply from: "$enableMPPWasmJs" +apply from: "$enableMPPAndroid" diff --git a/gradle/templates/mppJavaProject.gradle b/gradle/templates/mppJavaProject.gradle index f6c32dc..ad71124 100644 --- a/gradle/templates/mppJavaProject.gradle +++ b/gradle/templates/mppJavaProject.gradle @@ -1,39 +1,2 @@ -project.version = "$version" -project.group = "$group" - -// apply from: "$publishGradlePath" - -kotlin { - jvm { - compilations.main { - kotlinOptions { - jvmTarget = "17" - } - } - } - - sourceSets { - commonMain { - dependencies { - implementation libs.kotlin - api libs.kotlin.serialization - } - } - commonTest { - dependencies { - implementation libs.kotlin.test.common - implementation libs.kotlin.test.annotations.common - } - } - jvmTest { - dependencies { - implementation libs.kotlin.test.junit - } - } - } -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} +apply from: "$defaultProject" +apply from: "$enableMPPJvm" diff --git a/gradle/templates/mppJsProject.gradle b/gradle/templates/mppJsProject.gradle index 7588b77..5af356b 100644 --- a/gradle/templates/mppJsProject.gradle +++ b/gradle/templates/mppJsProject.gradle @@ -1,31 +1,2 @@ -project.version = "$version" -project.group = "$group" - -// apply from: "$publishGradlePath" - -kotlin { - js (IR) { - browser() - nodejs() - } - - sourceSets { - commonMain { - dependencies { - implementation libs.kotlin - api libs.kotlin.serialization - } - } - commonTest { - dependencies { - implementation libs.kotlin.test.common - implementation libs.kotlin.test.annotations.common - } - } - jsTest { - dependencies { - implementation libs.kotlin.test.js - } - } - } -} +apply from: "$defaultProject" +apply from: "$enableMPPJs" diff --git a/gradle/templates/mppProjectWithSerialization.gradle b/gradle/templates/mppProjectWithSerialization.gradle index 584c4f5..513b979 100644 --- a/gradle/templates/mppProjectWithSerialization.gradle +++ b/gradle/templates/mppProjectWithSerialization.gradle @@ -1,65 +1,5 @@ -project.version = "$version" -project.group = "$group" - -// apply from: "$publishGradlePath" - -kotlin { - jvm { - compilations.main { - kotlinOptions { - jvmTarget = "17" - } - } - } - js (IR) { - browser() - nodejs() - } - androidTarget { - publishAllLibraryVariants() - compilations.all { - kotlinOptions { - jvmTarget = "17" - } - } - } - - sourceSets { - commonMain { - dependencies { - implementation libs.kotlin - api libs.kotlin.serialization - } - } - commonTest { - dependencies { - implementation libs.kotlin.test.common - implementation libs.kotlin.test.annotations.common - } - } - jvmTest { - dependencies { - implementation libs.kotlin.test.junit - } - } - jsTest { - dependencies { - implementation libs.kotlin.test.js - } - } - androidUnitTest { - dependencies { - implementation libs.kotlin.test.junit - implementation libs.android.test.junit - implementation libs.android.test.espresso.core - } - } - } -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -apply from: "$defaultAndroidSettings" +apply from: "$defaultProjectWithSerialization" +apply from: "$enableMPPJvm" +apply from: "$enableMPPJs" +apply from: "$enableMPPWasmJs" +apply from: "$enableMPPAndroid" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e382118..2733ed5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists