Fix plugin resolution

This commit is contained in:
Alexander Nozik 2021-09-13 22:49:41 +03:00
parent 878405ac6a
commit db9b4dec50
9 changed files with 46 additions and 30 deletions

View File

@ -21,8 +21,6 @@ repositories {
maven("https://repo.kotlin.link")
}
val kotlinVersion = "1.5.30"
java.targetCompatibility = JavaVersion.VERSION_11
kotlin.explicitApiWarning()
@ -35,6 +33,13 @@ dependencies {
implementation(libs.dokka.gradle)
implementation(libs.kotlin.jupyter.gradle)
implementation(libs.kotlin.serialization)
implementation("org.tomlj:tomlj:1.0.0")
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
//declaring exported plugins
@ -203,5 +208,6 @@ afterEvaluate {
}
tasks.processResources.configure {
duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.INCLUDE
from("gradle/libs.versions.toml")
}

View File

@ -82,7 +82,7 @@ public class KScienceExtension(public val project: Project) {
configuration: DependencyConfiguration = DependencyConfiguration.API,
block: SerializationTargets.() -> Unit = {},
): Unit = project.run {
apply("org.jetbrains.kotlin.plugin.serialization")
plugins.apply("org.jetbrains.kotlin.plugin.serialization")
val artifactName = if (version.startsWith("0")) {
"kotlinx-serialization-runtime"
} else {
@ -137,14 +137,14 @@ public class KScienceExtension(public val project: Project) {
*/
@Deprecated("Use jupyterLibrary")
public fun useJupyter() {
project.apply("org.jetbrains.kotlin.jupyter.api")
project.plugins.apply("org.jetbrains.kotlin.jupyter.api")
}
/**
* Apply jupyter plugin and add entry point for the jupyter library
*/
public fun jupyterLibrary(pluginClass: String, vararg additionalPluginClasses: String) {
project.apply("org.jetbrains.kotlin.jupyter.api")
project.plugins.apply("org.jetbrains.kotlin.jupyter.api")
project.tasks.named("processJupyterApiResources", JupyterApiResourcesTask::class.java) {
libraryProducers = listOf(pluginClass, *additionalPluginClasses)
}

View File

@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.apply
public open class KScienceJSPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
if (!plugins.hasPlugin("org.jetbrains.kotlin.js")) {
apply("org.jetbrains.kotlin.js")
plugins.apply("org.jetbrains.kotlin.js")
} else {
logger.info("Kotlin JS plugin is already present")
}

View File

@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.apply
public open class KScienceJVMPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
if (!plugins.hasPlugin("org.jetbrains.kotlin.jvm"))
apply("org.jetbrains.kotlin.jvm")
plugins.apply("org.jetbrains.kotlin.jvm")
else
logger.info("Kotlin JVM plugin is already present")

View File

@ -3,11 +3,13 @@ package ru.mipt.npm.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
public open class KScienceMPPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
apply("org.jetbrains.kotlin.multiplatform")
if (!plugins.hasPlugin(KotlinMultiplatformPlugin::class)) {
//apply<KotlinMultiplatformPlugin>() for some reason it does not work
plugins.apply("org.jetbrains.kotlin.multiplatform")
} else {
logger.info("Kotlin MPP plugin is already present")
}

View File

@ -10,7 +10,7 @@ public class KScienceNativePlugin : Plugin<Project> {
//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")
apply("org.jetbrains.kotlin.multiplatform")
plugins.apply("org.jetbrains.kotlin.multiplatform")
}
if (!plugins.hasPlugin(KScienceCommonPlugin::class)) {

View File

@ -2,10 +2,7 @@ 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.configure
import org.gradle.kotlin.dsl.findPlugin
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
/**
@ -16,7 +13,7 @@ public class KScienceNodePlugin : Plugin<Project> {
//Apply multiplatform plugin is not applied, apply it
if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) {
logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically")
apply("org.jetbrains.kotlin.multiplatform")
plugins.apply("org.jetbrains.kotlin.multiplatform")
}
if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {

View File

@ -1,31 +1,32 @@
package ru.mipt.npm.gradle
import org.gradle.api.JavaVersion
import org.gradle.internal.impldep.org.tomlj.Toml
import org.tomlj.Toml
/**
* Build constants
*/
public object KScienceVersions {
private val toml =
Toml.parse(KScienceVersions.javaClass.getResource("/libs.versions.toml")!!.readText())
private val toml by lazy {
Toml.parse(javaClass.getResource("/libs.versions.toml")!!.readText())
}
public val kotlinVersion: String = toml.getString("versions.kotlin")!!
public val kotlinxNodeVersion: String = toml.getString("versions.kotlinx-nodejs")!!
public val coroutinesVersion: String = toml.getString("versions.kotlinx-coroutines")!!
public val serializationVersion: String = toml.getString("versions.kotlinx-serialization")!!
public val atomicVersion: String = toml.getString("versions.atomicfu")!!
public val ktorVersion: String = toml.getString("versions.ktor")!!
public val htmlVersion: String = toml.getString("versions.kotlinx-html")!!
public val dateTimeVersion: String = toml.getString("versions.kotlinx-datetime")!!
public val jsBom: String = toml.getString("versions.jsBom")!!
public val kotlinVersion: String get() = toml.getString("versions.kotlin")!!
public val kotlinxNodeVersion: String get() = toml.getString("versions.kotlinx-nodejs")!!
public val coroutinesVersion: String get() = toml.getString("versions.kotlinx-coroutines")!!
public val serializationVersion: String get() = toml.getString("versions.kotlinx-serialization")!!
public val atomicVersion: String get() = toml.getString("versions.atomicfu")!!
public val ktorVersion: String get() = toml.getString("versions.ktor")!!
public val htmlVersion: String get() = toml.getString("versions.kotlinx-html")!!
public val dateTimeVersion: String get() = toml.getString("versions.kotlinx-datetime")!!
public val jsBom: String get() = toml.getString("versions.jsBom")!!
public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11
public object Serialization {
public val xmlVersion: String = toml.getString("versions.xmlutil")!!
public val yamlKtVersion: String = toml.getString("versions.yamlkt")!!
public val xmlVersion: String get() = toml.getString("versions.xmlutil")!!
public val yamlKtVersion: String get() = toml.getString("versions.yamlkt")!!
}
}

View File

@ -0,0 +1,10 @@
package ru.mipt.npm.gradle
import org.junit.jupiter.api.Test
class TestPlugins {
@Test
fun testVersions() {
println(KScienceVersions.coroutinesVersion)
}
}