Skip to content

Commit b2b4018

Browse files
authored
Merge pull request #23 from tuuhin/bugfix/dependency-resolution
Bugfix: Replacing version catalog dependencies references
2 parents 5b2ad59 + 43cf708 commit b2b4018

4 files changed

Lines changed: 23 additions & 42 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
.idea/
66
.kotlin/
77
build
8+
.junie/

plugin-build/plugin/src/main/kotlin/dev/nucleusframework/nna/plugin/KotlinNativeExportPlugin.kt

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package dev.nucleusframework.nna.plugin
22

3-
import dev.nucleusframework.nna.plugin.catalog.kotlinEmbeddedCompiler
4-
import dev.nucleusframework.nna.plugin.catalog.kotlinxCoroutineDependency
5-
import dev.nucleusframework.nna.plugin.catalog.kotlinxCoroutineJvmDependency
6-
import dev.nucleusframework.nna.plugin.catalog.kotlinxCoroutineTestDependency
73
import dev.nucleusframework.nna.plugin.tasks.GenerateNativeBridgesTask
84
import org.gradle.api.GradleException
95
import org.gradle.api.Plugin
106
import org.gradle.api.Project
7+
import org.gradle.api.artifacts.VersionCatalog
8+
import org.gradle.api.artifacts.VersionCatalogsExtension
119
import org.gradle.api.logging.LogLevel
1210
import org.gradle.api.tasks.testing.Test
13-
import org.gradle.kotlin.dsl.create
14-
import org.gradle.kotlin.dsl.getByType
15-
import org.gradle.kotlin.dsl.register
16-
import org.gradle.kotlin.dsl.withType
11+
import org.gradle.kotlin.dsl.*
1712
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
13+
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
1814
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
1915
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
2016
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
2117
import java.io.File
18+
import kotlin.jvm.optionals.getOrNull
2219

2320
/**
2421
* Main entry point for the kotlin-native-export Gradle plugin.
@@ -108,7 +105,9 @@ class KotlinNativeExportPlugin : Plugin<Project> {
108105
extendsFrom(knePsiScope)
109106
description = "Classpath for KNE PSI resolution"
110107
}
111-
project.dependencies.add(knePsiScope.name, project.kotlinEmbeddedCompiler)
108+
// using the project kotlin version for embedded kotlin
109+
val kotlinVersion = project.extensions.findByType<KotlinProjectExtension>()?.coreLibrariesVersion
110+
project.dependencies.add(knePsiScope.name, "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
112111

113112
// ── Code-generation tasks ────────────────────────────────────────────
114113

@@ -128,21 +127,24 @@ class KotlinNativeExportPlugin : Plugin<Project> {
128127
// Keep old task name as alias
129128
project.tasks.register("generateKneJvmProxies") { dependsOn(generateBridges) }
130129

131-
// ── Coroutines dependency (required for suspend function support) ──
130+
// read the kotlinx coroutines version from the catalog otherwise fallback to some version
131+
val coroutinesVersion = project.versionCatalog
132+
?.findVersion("kotlinx-coroutines")?.getOrNull()?.toString() ?: "1.11.0"
133+
132134
nativeTarget?.let { target ->
133135
kotlin.sourceSets.findByName("${target.name}Main")?.dependencies {
134-
implementation(project.kotlinxCoroutineDependency)
136+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
135137
}
136138
}
137139
kotlin.sourceSets.findByName("nativeMain")?.dependencies {
138-
implementation(project.kotlinxCoroutineDependency)
140+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
139141
}
140142

141143
kotlin.sourceSets.findByName(jvmMainSourceSetName)?.dependencies {
142-
implementation(project.kotlinxCoroutineJvmDependency)
144+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$coroutinesVersion")
143145
}
144146
kotlin.sourceSets.findByName(jvmTestSourceSetName)?.dependencies {
145-
implementation(project.kotlinxCoroutineTestDependency)
147+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
146148
}
147149

148150
// Wire generated bridges into the native source set (try nativeMain, fall back to <target>Main)
@@ -291,4 +293,10 @@ class KotlinNativeExportPlugin : Plugin<Project> {
291293
)
292294
}
293295
}
296+
297+
private val Project.versionCatalog: VersionCatalog?
298+
get() {
299+
val catalogs = project.extensions.getByType<VersionCatalogsExtension>()
300+
return catalogs.find("libs").getOrNull()
301+
}
294302
}

plugin-build/plugin/src/main/kotlin/dev/nucleusframework/nna/plugin/catalog/Libraries.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

plugin-build/plugin/src/main/kotlin/dev/nucleusframework/nna/plugin/catalog/VersionCatalog.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)