1- import com.saveourtool.save.buildutils.configureDetekt
2- import com.saveourtool.save.buildutils.configureDiktat
3- import com.saveourtool.save.buildutils.configurePublishing
4-
51import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem
6- import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
2+ import org.gradle.nativeplatform.platform.internal.DefaultOperatingSystem
3+ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
74
85plugins {
9- kotlin(" multiplatform" )
6+ application
7+ id(" com.saveourtool.save.buildutils.kotlin-library" )
108}
119
1210kotlin {
13- jvm()
1411 val os = getCurrentOperatingSystem()
15- val saveTarget = listOf (when {
16- os.isWindows -> mingwX64()
17- os.isLinux -> linuxX64()
18- os.isMacOsX -> macosX64()
19- else -> throw GradleException (" Unknown operating system $os " )
20- })
2112
22- configure(saveTarget) {
23- binaries {
24- val name = " save-${project.version} -${this @configure.name} "
25- executable {
26- this .baseName = name
27- entryPoint = " com.saveourtool.save.cli.main"
28- }
29- }
30- }
13+ jvm()
14+
15+ registerNativeBinaries(os, this )
3116
3217 sourceSets {
33- all {
34- languageSettings.optIn(" kotlin.RequiresOptIn" )
18+ val commonMain by getting {
19+ dependencies {
20+ api(libs.okio)
21+ }
3522 }
36- val jvmMain by getting
3723
38- val commonMain by getting
39- val nativeMain by creating {
40- dependsOn(commonMain)
24+ val commonNonJsMain by getting {
4125 dependencies {
4226 implementation(projects.saveCore)
27+ implementation(projects.saveCommon)
4328 implementation(libs.kotlinx.serialization.properties)
4429 }
4530 }
46- saveTarget.forEach {
47- getByName(" ${it.name} Main" ).dependsOn(nativeMain)
48- }
49-
50- val commonTest by getting
5131
5232 val jvmTest by getting {
5333 dependencies {
@@ -61,6 +41,46 @@ kotlin {
6141 }
6242 }
6343
44+ linkProperExecutable(os)
45+
46+ tasks.withType<Test >().configureEach {
47+ dependsOn(" :save-core:downloadTestResources" )
48+ }
49+ }
50+
51+ application {
52+ mainClass.set(" com.saveourtool.save.cli.SaveCliRunnerKt" )
53+ }
54+
55+ /* *
56+ * @param os
57+ * @param kotlin
58+ * @throws GradleException
59+ */
60+ fun registerNativeBinaries (os : DefaultOperatingSystem , kotlin : KotlinMultiplatformExtension ) {
61+ val saveTarget = when {
62+ os.isWindows -> kotlin.mingwX64()
63+ os.isLinux -> kotlin.linuxX64()
64+ os.isMacOsX -> kotlin.macosX64()
65+ else -> throw GradleException (" Unknown operating system $os " )
66+ }
67+
68+ configure(listOf (saveTarget)) {
69+ binaries {
70+ val name = " save-${project.version} -${this @configure.name} "
71+ executable {
72+ this .baseName = name
73+ entryPoint = " com.saveourtool.save.cli.main"
74+ }
75+ }
76+ }
77+ }
78+
79+ /* *
80+ * @param os
81+ * @throws GradleException
82+ */
83+ fun linkProperExecutable (os : DefaultOperatingSystem ) {
6484 val linkReleaseExecutableTaskProvider = when {
6585 os.isLinux -> tasks.getByName(" linkReleaseExecutableLinuxX64" )
6686 os.isWindows -> tasks.getByName(" linkReleaseExecutableMingwX64" )
@@ -71,6 +91,13 @@ kotlin {
7191 dependsOn(linkReleaseExecutableTaskProvider)
7292 }
7393
94+ // disable building of some binaries to speed up build
95+ // possible values: `all` - build all binaries, `debug` - build only debug binaries
96+ val enabledExecutables = if (hasProperty(" enabledExecutables" )) property(" enabledExecutables" ) as String else null
97+ if (enabledExecutables != null && enabledExecutables != " all" ) {
98+ linkReleaseExecutableTaskProvider.enabled = false
99+ }
100+
74101 // Integration test should be able to have access to binary during the execution. Also we use here the debug version,
75102 // in aim to have ability to run it in CI, which operates only with debug versions
76103 tasks.getByName(" jvmTest" ).dependsOn(tasks.getByName(
@@ -81,23 +108,8 @@ kotlin {
81108 else -> throw GradleException (" Unknown operating system $os " )
82109 }
83110 ))
84-
85- tasks.withType<Test >().configureEach {
86- dependsOn(" :save-core:downloadTestResources" )
87- }
88-
89- // disable building of some binaries to speed up build
90- // possible values: `all` - build all binaries, `debug` - build only debug binaries
91- val enabledExecutables = if (hasProperty(" enabledExecutables" )) property(" enabledExecutables" ) as String else null
92- if (enabledExecutables != null && enabledExecutables != " all" || enabledExecutables == " debug" ) {
93- linkReleaseExecutableTaskProvider.enabled = false
94- }
95111}
96112
97- configurePublishing()
98- configureDiktat()
99- configureDetekt()
100-
101- tasks.withType<KotlinJvmTest > {
102- useJUnitPlatform()
113+ application {
114+ mainClass.set(" com.saveourtool.save.cli.SaveCliRunnerKt" )
103115}
0 commit comments