From b4f494e58ac5e7040bd55c11d90ec673138c27c2 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 24 Aug 2022 19:02:19 +0300 Subject: [PATCH] Revert native plugin configuration --- .../kscience/gradle/KScienceNativePlugin.kt | 51 ++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/space/kscience/gradle/KScienceNativePlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceNativePlugin.kt index a41fbf6..5b86fea 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceNativePlugin.kt @@ -2,24 +2,61 @@ package space.kscience.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.hasPlugin +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +@Deprecated("Use common configuration block") public class KScienceNativePlugin : Plugin { override fun apply(project: Project): Unit = project.run { + logger.warn("Native plugin is deprecated. Use `ksceince.native()`") + //Apply multiplatform plugin is not applied, apply it if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") plugins.apply("org.jetbrains.kotlin.multiplatform") } - registerKScienceExtension(::KScienceMppExtension).apply { - native() + if (!plugins.hasPlugin(KScienceCommonPlugin::class)) { + logger.info("KScience plugin is not resolved. Adding it automatically") + apply() } - if (!plugins.hasPlugin(KScienceCommonPlugin::class)) { - configureKScience() - } else { - project.logger.warn("Use `kscience.native()` configuration block") + configure { + val nativeTargets = setOf( + linuxX64(), + mingwX64(), + macosX64(), + iosX64(), + iosArm64() + ) + + sourceSets { + val commonMain = findByName("commonMain")!! + val commonTest = findByName("commonTest")!! + + val nativeMain by creating { + dependsOn(commonMain) + } + + val nativeTest by creating { + //should NOT depend on nativeMain because automatic dependency by plugin + dependsOn(commonTest) + } + + configure(nativeTargets) { + compilations["main"]?.apply { + configure(kotlinSourceSets) { + dependsOn(nativeMain) + } + } + + compilations["test"]?.apply { + configure(kotlinSourceSets) { + dependsOn(nativeTest) + } + } + } + } } } }