Fix dependency configuration

This commit is contained in:
Alexander Nozik 2020-11-25 14:26:08 +03:00
parent f456be46d4
commit 723a959a0b
5 changed files with 62 additions and 62 deletions

View File

@ -19,6 +19,7 @@ open class KScienceCommonPlugin : Plugin<Project> {
//Configuration for K-JVM plugin //Configuration for K-JVM plugin
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
//logger.info("Applying KScience configuration for JVM project")
configure<KotlinJvmProjectExtension> { configure<KotlinJvmProjectExtension> {
explicitApiWarning() explicitApiWarning()
@ -37,6 +38,7 @@ open class KScienceCommonPlugin : Plugin<Project> {
} }
pluginManager.withPlugin("org.jetbrains.kotlin.js") { pluginManager.withPlugin("org.jetbrains.kotlin.js") {
//logger.info("Applying KScience configuration for JS project")
configure<KotlinJsProjectExtension> { configure<KotlinJsProjectExtension> {
explicitApiWarning() explicitApiWarning()
@ -117,7 +119,7 @@ open class KScienceCommonPlugin : Plugin<Project> {
tasks.apply { tasks.apply {
withType<KotlinJvmCompile> { withType<KotlinJvmCompile> {
kotlinOptions { kotlinOptions {
// useIR = true // useIR = true
jvmTarget = KScienceVersions.JVM_TARGET.toString() jvmTarget = KScienceVersions.JVM_TARGET.toString()
} }
} }

View File

@ -3,14 +3,12 @@ package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.findPlugin
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
open class KScienceMPPlugin : Plugin<Project> { open class KScienceMPPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { 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") 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) plugins.apply(KScienceCommonPlugin::class)
} }

View File

@ -5,14 +5,13 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
class KScienceNativePlugin : Plugin<Project> { class KScienceNativePlugin : Plugin<Project> {
override fun apply(target: Project) = target.run { override fun apply(target: Project) = target.run {
//Apply multiplatform plugin is not applied, apply it //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") 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) { if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
logger.info("KScience plugin is not resolved. Adding it automatically") logger.info("KScience plugin is not resolved. Adding it automatically")

View File

@ -4,7 +4,6 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
/** /**
* Create a separate target for node * Create a separate target for node
@ -12,9 +11,9 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
class KScienceNodePlugin : Plugin<Project> { class KScienceNodePlugin : Plugin<Project> {
override fun apply(target: Project) = target.run { override fun apply(target: Project) = target.run {
//Apply multiplatform plugin is not applied, apply it //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") 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) { if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
logger.info("KScience plugin is not resolved. Adding it automatically") logger.info("KScience plugin is not resolved. Adding it automatically")

View File

@ -1,8 +1,7 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle
import kotlinx.atomicfu.plugin.gradle.sourceSets
import org.gradle.api.Project 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.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
@ -23,7 +22,7 @@ internal fun Project.useDependency(
dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION
) { ) {
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
extensions.findByType<KotlinMultiplatformExtension>()?.apply { configure<KotlinMultiplatformExtension> {
sourceSets { sourceSets {
pairs.forEach { (target, dep) -> pairs.forEach { (target, dep) ->
val name = target + dependencySourceSet.suffix 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") { pairs.find { it.first == "jvm" }?.let { dep ->
sourceSets.findByName(dependencySourceSet.setName)?.apply { pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
dependencies.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {
val configurationName = when (dependencyConfiguration) { dependencies.apply {
DependencyConfiguration.API -> apiConfigurationName val configurationName = when (dependencyConfiguration) {
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName DependencyConfiguration.API -> apiConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName 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, dep: String,
dependencySourceSet: DependencySourceSet = DependencySourceSet.MAIN, dependencySourceSet: DependencySourceSet = DependencySourceSet.MAIN,
dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION
): Unit = pluginManager.run{ ): Unit = pluginManager.run {
withPlugin("org.jetbrains.kotlin.multiplatform"){ withPlugin("org.jetbrains.kotlin.multiplatform") {
extensions.findByType<KotlinMultiplatformExtension>()?.apply { configure<KotlinMultiplatformExtension> {
sourceSets.findByName("common${dependencySourceSet.suffix}")?.apply { sourceSets.findByName("common${dependencySourceSet.suffix}")?.apply {
dependencies { dependencies {
when (dependencyConfiguration) { when (dependencyConfiguration) {
@ -88,29 +89,30 @@ internal fun Project.useCommonDependency(
} }
} }
} }
}
} withPlugin("org.jetbrains.kotlin.jvm") {
withPlugin("org.jetbrains.kotlin.jvm") { sourceSets.findByName(dependencySourceSet.setName)?.apply {
sourceSets.findByName(dependencySourceSet.setName)?.apply { dependencies.apply {
dependencies.apply { val configurationName = when (dependencyConfiguration) {
val configurationName = when (dependencyConfiguration) { DependencyConfiguration.API -> apiConfigurationName
DependencyConfiguration.API -> apiConfigurationName DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName }
add(configurationName, dep)
}
} }
add(configurationName, dep)
} }
} withPlugin("org.jetbrains.kotlin.js") {
} sourceSets.findByName(dependencySourceSet.setName)?.apply {
withPlugin("org.jetbrains.kotlin.js") { dependencies.apply {
sourceSets.findByName(dependencySourceSet.setName)?.apply { val configurationName = when (dependencyConfiguration) {
dependencies.apply { DependencyConfiguration.API -> apiConfigurationName
val configurationName = when (dependencyConfiguration) { DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName
DependencyConfiguration.API -> apiConfigurationName DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName }
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName add(configurationName, dep)
}
} }
add(configurationName, dep)
} }
} }
} }