Skip to content

Commit 0889352

Browse files
committed
kmm gradle config tidy up
1 parent c78b77a commit 0889352

File tree

5 files changed

+81
-43
lines changed

5 files changed

+81
-43
lines changed

buildSrc/src/main/kotlin/buildsrc/config/gradle.kt

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,3 @@ fun IdeaModule.excludeGeneratedGradleDsl(layout: ProjectLayout) {
2727
)
2828
)
2929
}
30-
31-
32-
/**
33-
* `kotlin-js` adds a directory in the root-dir for the Yarn lock.
34-
* That's a bit annoying. It's a little neater if it's in the
35-
* gradle dir, next to the version-catalog.
36-
*/
37-
fun Project.relocateKotlinJsStore() {
38-
39-
afterEvaluate {
40-
rootProject.extensions.findByType<YarnRootExtension>()?.apply {
41-
lockFileDirectory = project.rootDir.resolve("gradle/kotlin-js-store")
42-
}
43-
}
44-
45-
}
46-
47-
fun KotlinTargetContainerWithPresetFunctions.currentHostTarget(
48-
targetName: String = "native",
49-
configure: KotlinNativeTargetWithHostTests.() -> Unit,
50-
): KotlinNativeTargetWithHostTests {
51-
val hostOs = System.getProperty("os.name")
52-
val isMingwX64 = hostOs.startsWith("Windows")
53-
val hostTarget = when {
54-
hostOs == "Mac OS X" -> macosX64(targetName)
55-
hostOs == "Linux" -> linuxX64(targetName)
56-
isMingwX64 -> mingwX64(targetName)
57-
else -> throw GradleException("Preset for host OS '$hostOs' is undefined")
58-
}
59-
println("Current host target ${hostTarget.targetName}/${hostTarget.preset?.name}")
60-
hostTarget.configure()
61-
return hostTarget
62-
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package buildsrc.config
2+
3+
import org.gradle.api.GradleException
4+
import org.gradle.api.Project
5+
import org.gradle.kotlin.dsl.findByType
6+
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
7+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
8+
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
9+
10+
11+
/**
12+
* `kotlin-js` adds a directory in the root-dir for the Yarn lock.
13+
* That's a bit annoying. It's a little neater if it's in the
14+
* gradle dir, next to the version-catalog.
15+
*/
16+
fun Project.relocateKotlinJsStore() {
17+
18+
afterEvaluate {
19+
rootProject.extensions.findByType<YarnRootExtension>()?.apply {
20+
lockFileDirectory = project.rootDir.resolve("gradle/kotlin-js-store")
21+
}
22+
}
23+
24+
}
25+
26+
27+
fun KotlinMultiplatformExtension.currentHostTarget(
28+
targetName: String = "native",
29+
configure: KotlinNativeTargetWithHostTests.() -> Unit,
30+
): KotlinNativeTargetWithHostTests {
31+
val hostOs = System.getProperty("os.name")
32+
val hostTarget = when {
33+
hostOs == "Mac OS X" -> macosX64(targetName)
34+
hostOs == "Linux" -> linuxX64(targetName)
35+
hostOs.startsWith("Windows") -> mingwX64(targetName)
36+
else -> throw GradleException("Preset for host OS '$hostOs' is undefined")
37+
}
38+
39+
println("Current host target ${hostTarget.targetName}/${hostTarget.preset?.name}")
40+
hostTarget.configure()
41+
return hostTarget
42+
}
43+
44+
45+
fun KotlinMultiplatformExtension.publicationsFromMainHost(): List<String> {
46+
return listOf(jvm(), js()).map { it.name } + "kotlinMultiplatform"
47+
}

buildSrc/src/main/kotlin/buildsrc/convention/kotlin-multiplatform.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package buildsrc.convention
22

33
import buildsrc.config.relocateKotlinJsStore
44

5+
56
plugins {
67
id("buildsrc.convention.subproject")
78
kotlin("multiplatform")
@@ -10,3 +11,15 @@ plugins {
1011

1112

1213
relocateKotlinJsStore()
14+
15+
16+
kotlin {
17+
targets.all {
18+
compilations.all {
19+
kotlinOptions {
20+
languageVersion = "1.6"
21+
apiVersion = "1.6"
22+
}
23+
}
24+
}
25+
}

modules/kxs-ts-gen-core/build.gradle.kts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import buildsrc.config.publicationsFromMainHost
2+
3+
14
plugins {
25
buildsrc.convention.`kotlin-multiplatform`
36
buildsrc.convention.`maven-publish`
@@ -8,14 +11,6 @@ plugins {
811
val kotlinxSerializationVersion = "1.3.2"
912

1013
kotlin {
11-
// val hostOs = System.getProperty("os.name")
12-
// val isMingwX64 = hostOs.startsWith("Windows")
13-
// val nativeTarget = when {
14-
// hostOs == "Mac OS X" -> macosX64("native")
15-
// hostOs == "Linux" -> linuxX64("native")
16-
// isMingwX64 -> mingwX64("native")
17-
// else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
18-
// }
1914

2015
// js(IR) {
2116
// binaries.executable()
@@ -25,19 +20,30 @@ kotlin {
2520
// }
2621
// }
2722
// }
23+
2824
jvm {
2925
compilations.all {
3026
kotlinOptions {
3127
jvmTarget = "11"
32-
languageVersion = "1.6"
33-
apiVersion = "1.6"
3428
}
3529
}
3630
withJava()
3731
testRuns["test"].executionTask.configure {
3832
useJUnitPlatform()
3933
}
4034
}
35+
36+
// publishing {
37+
// publications {
38+
// matching { it.name in publicationsFromMainHost() }.all {
39+
// val targetPublication = this@all
40+
// tasks.withType<AbstractPublishToMaven>()
41+
// .matching { it.publication == targetPublication }
42+
// .configureEach { onlyIf { findProperty("isMainHost") == "true" } }
43+
// }
44+
// }
45+
// }
46+
4147
sourceSets {
4248

4349
all {

settings.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ include(
99
)
1010

1111
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
12+
13+
dependencyResolutionManagement {
14+
@Suppress("UnstableApiUsage") // Central declaration of repositories is an incubating feature
15+
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
16+
}

0 commit comments

Comments
 (0)