11package 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
73import dev.nucleusframework.nna.plugin.tasks.GenerateNativeBridgesTask
84import org.gradle.api.GradleException
95import org.gradle.api.Plugin
106import org.gradle.api.Project
7+ import org.gradle.api.artifacts.VersionCatalog
8+ import org.gradle.api.artifacts.VersionCatalogsExtension
119import org.gradle.api.logging.LogLevel
1210import 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.*
1712import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
13+ import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
1814import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
1915import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
2016import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
2117import 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}
0 commit comments