From 723a959a0bf5e081391e3b35720035bb7d72c600 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 25 Nov 2020 14:26:08 +0300 Subject: [PATCH] Fix dependency configuration --- .../mipt/npm/gradle/KScienceCommonPlugin.kt | 4 +- .../ru/mipt/npm/gradle/KScienceMPPlugin.kt | 6 +- .../mipt/npm/gradle/KScienceNativePlugin.kt | 5 +- .../ru/mipt/npm/gradle/KScienceNodePlugin.kt | 5 +- .../kotlin/ru/mipt/npm/gradle/dependencies.kt | 104 +++++++++--------- 5 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt index 124926c..ace2634 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceCommonPlugin.kt @@ -19,6 +19,7 @@ open class KScienceCommonPlugin : Plugin { //Configuration for K-JVM plugin pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + //logger.info("Applying KScience configuration for JVM project") configure { explicitApiWarning() @@ -37,6 +38,7 @@ open class KScienceCommonPlugin : Plugin { } pluginManager.withPlugin("org.jetbrains.kotlin.js") { + //logger.info("Applying KScience configuration for JS project") configure { explicitApiWarning() @@ -117,7 +119,7 @@ open class KScienceCommonPlugin : Plugin { tasks.apply { withType { kotlinOptions { -// useIR = true + // useIR = true jvmTarget = KScienceVersions.JVM_TARGET.toString() } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index ef0a7de..92a97d3 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -3,14 +3,12 @@ package ru.mipt.npm.gradle import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.findPlugin -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin open class KScienceMPPlugin : Plugin { override fun apply(project: Project): Unit = project.run { - if (plugins.findPlugin(KotlinMultiplatformPlugin::class) == null) { + if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") - pluginManager.apply(KotlinMultiplatformPlugin::class) + pluginManager.apply("org.jetbrains.kotlin.multiplatform") } plugins.apply(KScienceCommonPlugin::class) } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt index 80c5cdf..c507d49 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNativePlugin.kt @@ -5,14 +5,13 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin class KScienceNativePlugin : Plugin { override fun apply(target: Project) = target.run { //Apply multiplatform plugin is not applied, apply it - if (plugins.findPlugin(KotlinMultiplatformPlugin::class) == null) { + if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") - pluginManager.apply(KotlinMultiplatformPlugin::class) + pluginManager.apply("org.jetbrains.kotlin.multiplatform") } if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { logger.info("KScience plugin is not resolved. Adding it automatically") diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt index a65229c..473424e 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt @@ -4,7 +4,6 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin /** * Create a separate target for node @@ -12,9 +11,9 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin class KScienceNodePlugin : Plugin { override fun apply(target: Project) = target.run { //Apply multiplatform plugin is not applied, apply it - if (plugins.findPlugin(KotlinMultiplatformPlugin::class) == null) { + if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") - pluginManager.apply(KotlinMultiplatformPlugin::class) + pluginManager.apply("org.jetbrains.kotlin.multiplatform") } if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { logger.info("KScience plugin is not resolved. Adding it automatically") diff --git a/src/main/kotlin/ru/mipt/npm/gradle/dependencies.kt b/src/main/kotlin/ru/mipt/npm/gradle/dependencies.kt index 4dcea9b..472d82a 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/dependencies.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/dependencies.kt @@ -1,8 +1,7 @@ package ru.mipt.npm.gradle -import kotlinx.atomicfu.plugin.gradle.sourceSets import org.gradle.api.Project -import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.invoke import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension @@ -23,7 +22,7 @@ internal fun Project.useDependency( dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION ) { pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - extensions.findByType()?.apply { + configure { sourceSets { pairs.forEach { (target, dep) -> val name = target + dependencySourceSet.suffix @@ -38,37 +37,39 @@ internal fun Project.useDependency( } } } - } - } - pairs.find { it.first == "jvm" }?.let { dep -> - pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - sourceSets.findByName(dependencySourceSet.setName)?.apply { - dependencies.apply { - val configurationName = when (dependencyConfiguration) { - DependencyConfiguration.API -> apiConfigurationName - DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName - DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + + pairs.find { it.first == "jvm" }?.let { dep -> + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + sourceSets.findByName(dependencySourceSet.setName)?.apply { + dependencies.apply { + val configurationName = when (dependencyConfiguration) { + DependencyConfiguration.API -> apiConfigurationName + DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName + DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + } + add(configurationName, dep.second) + } + } + } + } + + pairs.find { it.first == "js" }?.let { dep -> + pluginManager.withPlugin("org.jetbrains.kotlin.js") { + sourceSets.findByName(dependencySourceSet.setName)?.apply { + dependencies.apply { + val configurationName = when (dependencyConfiguration) { + DependencyConfiguration.API -> apiConfigurationName + DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName + DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + } + add(configurationName, dep.second) + } } - add(configurationName, dep.second) } } } - } - pairs.find { it.first == "js" }?.let { dep -> - pluginManager.withPlugin("org.jetbrains.kotlin.js") { - sourceSets.findByName(dependencySourceSet.setName)?.apply { - dependencies.apply { - val configurationName = when (dependencyConfiguration) { - DependencyConfiguration.API -> apiConfigurationName - DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName - DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName - } - add(configurationName, dep.second) - } - } - } } } @@ -76,9 +77,9 @@ internal fun Project.useCommonDependency( dep: String, dependencySourceSet: DependencySourceSet = DependencySourceSet.MAIN, dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION -): Unit = pluginManager.run{ - withPlugin("org.jetbrains.kotlin.multiplatform"){ - extensions.findByType()?.apply { +): Unit = pluginManager.run { + withPlugin("org.jetbrains.kotlin.multiplatform") { + configure { sourceSets.findByName("common${dependencySourceSet.suffix}")?.apply { dependencies { when (dependencyConfiguration) { @@ -88,29 +89,30 @@ internal fun Project.useCommonDependency( } } } - } - } - withPlugin("org.jetbrains.kotlin.jvm") { - sourceSets.findByName(dependencySourceSet.setName)?.apply { - dependencies.apply { - val configurationName = when (dependencyConfiguration) { - DependencyConfiguration.API -> apiConfigurationName - DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName - DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + + withPlugin("org.jetbrains.kotlin.jvm") { + sourceSets.findByName(dependencySourceSet.setName)?.apply { + dependencies.apply { + val configurationName = when (dependencyConfiguration) { + DependencyConfiguration.API -> apiConfigurationName + DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName + DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + } + add(configurationName, dep) + } } - add(configurationName, dep) } - } - } - withPlugin("org.jetbrains.kotlin.js") { - sourceSets.findByName(dependencySourceSet.setName)?.apply { - dependencies.apply { - val configurationName = when (dependencyConfiguration) { - DependencyConfiguration.API -> apiConfigurationName - DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName - DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + withPlugin("org.jetbrains.kotlin.js") { + sourceSets.findByName(dependencySourceSet.setName)?.apply { + dependencies.apply { + val configurationName = when (dependencyConfiguration) { + DependencyConfiguration.API -> apiConfigurationName + DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName + DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName + } + add(configurationName, dep) + } } - add(configurationName, dep) } } }