Skip to content

Commit 54943e3

Browse files
committed
chore: minor refactor to make mpp plugin more configurable
1 parent 3ed29ca commit 54943e3

File tree

8 files changed

+76
-76
lines changed

8 files changed

+76
-76
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ org-name = "suresh.dev"
2020
org-url = "https://suresh.dev"
2121

2222
# Gradle Dependencies Versions
23-
bc-plugins = "1.3.0"
23+
bc-plugins = "1.4.0"
2424
kotlinx-kover = "0.9.1"
2525
kotlinx-bcv = "0.17.0"
2626
kotlin-dokka = "2.0.0"
@@ -105,7 +105,7 @@ jspecify = "1.0.0"
105105
rsocket = "0.16.0"
106106
jctools = "4.0.5"
107107
kotlin-codepoints = "0.9.0"
108-
kotlin-logging = "7.0.3"
108+
kotlin-logging = "7.0.4"
109109
kotlin-bignum = "0.3.10"
110110
kotlin-diff = "0.7.0"
111111
kotlin-retry = "2.0.1"

plugins/project/src/main/kotlin/common/Multiplatform.kt

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -275,38 +275,33 @@ fun KotlinMultiplatformExtension.nativeTargets(
275275
configure: KotlinNativeTarget.() -> Unit = {}
276276
) =
277277
with(project) {
278-
val nativeBuild: String? by project
279-
val nativeWinTarget: String? by project
280-
281-
if (nativeBuild.toBoolean()) {
282-
fun KotlinNativeTarget.configureAll() {
283-
compilerOptions {
284-
// freeCompilerArgs.addAll("-Xverbose-phases=Linker", "-Xruntime-logs=gc=info")
285-
}
286-
configure()
287-
}
288-
278+
fun KotlinNativeTarget.configureAll() {
289279
compilerOptions {
290-
optIn.addAll(
291-
"kotlinx.cinterop.ExperimentalForeignApi",
292-
"kotlin.experimental.ExperimentalNativeApi",
293-
)
280+
// freeCompilerArgs.addAll("-Xverbose-phases=Linker", "-Xruntime-logs=gc=info")
294281
}
282+
configure()
283+
}
295284

296-
macosX64 { configureAll() }
297-
macosArm64 { configureAll() }
298-
linuxX64 { configureAll() }
299-
linuxArm64 { configureAll() }
300-
if (nativeWinTarget.toBoolean()) {
301-
mingwX64 { configureAll() }
302-
}
285+
compilerOptions {
286+
optIn.addAll(
287+
"kotlinx.cinterop.ExperimentalForeignApi",
288+
"kotlin.experimental.ExperimentalNativeApi",
289+
)
290+
}
303291

304-
sourceSets {
305-
nativeMain {
306-
dependencies {
307-
api(libs.ktor.client.cio)
308-
// api(libs.arrow.suspendapp.ktor)
309-
}
292+
macosX64 { configureAll() }
293+
macosArm64 { configureAll() }
294+
linuxX64 { configureAll() }
295+
linuxArm64 { configureAll() }
296+
if (isWinTargetEnabled) {
297+
mingwX64 { configureAll() }
298+
}
299+
300+
sourceSets {
301+
nativeMain {
302+
dependencies {
303+
api(libs.ktor.client.cio)
304+
// api(libs.arrow.suspendapp.ktor)
310305
}
311306
}
312307
}

plugins/project/src/main/kotlin/common/ProjectExtns.kt

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.gradle.api.artifacts.VersionCatalogsExtension
1818
import org.gradle.api.attributes.*
1919
import org.gradle.api.component.AdhocComponentWithVariants
2020
import org.gradle.api.plugins.JavaPluginExtension
21+
import org.gradle.api.provider.*
2122
import org.gradle.api.tasks.*
2223
import org.gradle.api.tasks.compile.JavaCompile
2324
import org.gradle.api.tasks.testing.*
@@ -59,25 +60,28 @@ val Project.buildLogicProjectName
5960
val Project.isSharedProject
6061
get() = name == sharedProjectName
6162

62-
// val debug: String? by project
63-
val Project.debugEnabled
64-
get() = providers.gradleProperty("debug").map(String::toBoolean).getOrElse(false)
65-
6663
val Project.skipTest
67-
get() = providers.gradleProperty("skip.test").map(String::toBoolean).getOrElse(false)
64+
get() = gradleBooleanProperty("skip.test").get()
6865

6966
val Project.hasCleanTask
7067
get() = gradle.startParameter.taskNames.any { it in listOf("clean", "cleanAll") }
7168

72-
val Project.isSnapshotVersion
73-
get() = version.toString().endsWith("SNAPSHOT", true)
74-
7569
val Project.runsOnCI
7670
get() = providers.environmentVariable("CI").isPresent
7771

72+
// val debug: String? by project
73+
val Project.debugEnabled
74+
get() = gradleBooleanProperty("debug").get()
75+
76+
val Project.isSnapshotVersion
77+
get() = version.toString().endsWith("SNAPSHOT", true)
78+
7879
val Project.isKmpExecEnabled
7980
get() = extra.has("enableKmpExec") && extra["enableKmpExec"] as Boolean
8081

82+
val Project.isWinTargetEnabled: Boolean
83+
get() = gradleBooleanProperty("kotlin.target.win.enabled").get()
84+
8185
/** Java version properties. */
8286
val Project.javaVersion
8387
get() = libs.versions.java.asProvider().map { JavaVersion.toVersion(it) }
@@ -110,6 +114,9 @@ val Project.kotlinLangVersion
110114
val Project.orgName
111115
get() = libs.versions.org.name.get()
112116

117+
val Project.orgUrl
118+
get() = libs.versions.org.url.get()
119+
113120
val Project.githubUser
114121
get() = libs.versions.dev.name.get().lowercase()
115122

@@ -713,6 +720,9 @@ fun Project.addFileToJavaComponent(file: File) {
713720
}
714721
}
715722

723+
fun Project.gradleBooleanProperty(name: String): Provider<Boolean> =
724+
providers.gradleProperty(name).map(String::toBoolean).orElse(false)
725+
716726
/** Lazy version of [TaskContainer.maybeCreate] */
717727
inline fun <reified T : Task> TaskContainer.maybeRegister(
718728
name: String,
@@ -727,23 +737,3 @@ inline fun <reified T : Task> TaskContainer.maybeRegister(
727737
it.configure(action)
728738
}
729739
}
730-
731-
/**
732-
* Generates the URL for the GitHub package repository based on the owner and repository name.
733-
*
734-
* @param owner The owner of the GitHub repository.
735-
* @param repository The name of the GitHub repository.
736-
* @return The URL of the GitHub package repository.
737-
*/
738-
fun githubPackage(owner: String, repository: String) =
739-
"https://maven.pkg.github.com/${owner.lowercase()}/$repository"
740-
741-
/**
742-
* Returns the latest download URL for a given [groupId] and [artifactId] from Maven Central.
743-
*
744-
* @param groupId the group ID of the Maven artifact
745-
* @param artifactId the artifact ID of the Maven artifact
746-
* @return the latest download URL for the specified Maven artifact
747-
*/
748-
fun mavenDownloadUrl(groupId: String, artifactId: String) =
749-
"https://search.maven.org/remote_content?g=${groupId}&a=${artifactId}&v=LATEST"

plugins/project/src/main/kotlin/dev.suresh.plugin.kotlin.mpp.gradle.kts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ configurations.configureEach { resolutionStrategy { failOnNonReproducibleResolut
3737

3838
kotlin {
3939
commonTarget(project)
40-
when (project.name) {
41-
sharedProjectName -> {
42-
jvmTarget(project)
43-
jsTarget(project)
44-
wasmJsTarget(project)
45-
nativeTargets(project) {}
46-
}
47-
48-
"web",
49-
"frontend" -> {
50-
jsTarget(project)
51-
wasmJsTarget(project)
52-
}
53-
}
5440

5541
// applyDefaultHierarchyTemplate {
5642
// common {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package common
2+
3+
import org.gradle.api.initialization.Settings
4+
import org.gradle.api.provider.Provider
5+
6+
val Settings.isNativeTargetEnabled: Boolean
7+
get() = gradleBooleanProperty("kotlin.target.native.enabled").get()
8+
9+
fun Settings.gradleBooleanProperty(name: String): Provider<Boolean> =
10+
providers.gradleProperty(name).map(String::toBoolean).orElse(false)

plugins/shared/src/main/kotlin/common/Extns.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import kotlin.math.pow
1212
import kotlin.properties.ReadOnlyProperty
1313
import kotlin.reflect.full.isSubtypeOf
1414
import kotlin.reflect.typeOf
15-
import kotlinx.coroutines.*
1615

1716
internal val DEC_FORMAT = DecimalFormat("#.##")
1817

@@ -152,3 +151,23 @@ inline fun <reified T> sysProp(): ReadOnlyProperty<Any?, T> = ReadOnlyProperty {
152151
}
153152
as T
154153
}
154+
155+
/**
156+
* Generates the URL for the GitHub package repository based on the owner and repository name.
157+
*
158+
* @param owner The owner of the GitHub repository.
159+
* @param repository The name of the GitHub repository.
160+
* @return The URL of the GitHub package repository.
161+
*/
162+
fun githubPackage(owner: String, repository: String) =
163+
"https://maven.pkg.github.com/${owner.lowercase()}/$repository"
164+
165+
/**
166+
* Returns the latest download URL for a given [groupId] and [artifactId] from Maven Central.
167+
*
168+
* @param groupId the group ID of the Maven artifact
169+
* @param artifactId the artifact ID of the Maven artifact
170+
* @return the latest download URL for the specified Maven artifact
171+
*/
172+
fun mavenDownloadUrl(groupId: String, artifactId: String) =
173+
"https://search.maven.org/remote_content?g=${groupId}&a=${artifactId}&v=LATEST"

sandbox/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import common.*
22
import org.gradle.kotlin.dsl.*
33
import tasks.*
44

5-
val enableExec by extra(false)
5+
val enableKmpExec by extra(false)
66

77
plugins {
88
id("dev.suresh.plugin.root") version "+"

sandbox/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ semver.logOnlyOnRootProject=true
5959
enableMavenSnapshot=false
6060
debug=false
6161

62-
# Sandbox Testing
63-
# test.version=x.y.z
62+
kotlin.target.native.enabled=false
63+
kotlin.target.win.enabled=false

0 commit comments

Comments
 (0)