Remove old plugins make native configurable inside kscience block.
This commit is contained in:
parent
b4f494e58a
commit
5dacf9c9d6
@ -51,12 +51,6 @@ tasks.test {
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("common") {
|
||||
id = "space.kscience.gradle.common"
|
||||
description = "The generalized kscience plugin that works in conjunction with any kotlin plugin"
|
||||
implementationClass = "space.kscience.gradle.KScienceCommonPlugin"
|
||||
}
|
||||
|
||||
create("project") {
|
||||
id = "space.kscience.gradle.project"
|
||||
description = "The root plugin for multi-module project infrastructure"
|
||||
@ -80,18 +74,6 @@ gradlePlugin {
|
||||
description = "Pre-configured JS project"
|
||||
implementationClass = "space.kscience.gradle.KScienceJSPlugin"
|
||||
}
|
||||
|
||||
create("native") {
|
||||
id = "space.kscience.gradle.native"
|
||||
description = "Additional native targets to be use alongside mpp"
|
||||
implementationClass = "space.kscience.gradle.KScienceNativePlugin"
|
||||
}
|
||||
|
||||
create("node") {
|
||||
id = "space.kscience.gradle.node"
|
||||
description = "Additional nodejs target to be use alongside mpp"
|
||||
implementationClass = "space.kscience.gradle.KScienceNodePlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,7 +90,6 @@ tasks.create("version") {
|
||||
|
||||
//publishing version catalog
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
catalog.versionCatalog {
|
||||
from(files("gradle/libs.versions.toml"))
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
tools = "0.12.1-kotlin-1.7.20-Beta"
|
||||
tools = "0.13.0-kotlin-1.7.20-Beta"
|
||||
kotlin = "1.7.20-Beta"
|
||||
atomicfu = "0.18.2"
|
||||
binary-compatibility-validator = "0.10.1"
|
||||
|
@ -1,8 +0,0 @@
|
||||
package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
public open class KScienceCommonPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project): Unit = project.configureKScience()
|
||||
}
|
@ -2,12 +2,12 @@ package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.ApplicationPlugin
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.findByType
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
@ -138,6 +138,33 @@ public open class KScienceExtension(public val project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public fun dependencies(sourceSet: String? = null, dependencyBlock: KotlinDependencyHandler.() -> Unit) {
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||
project.configure<KotlinJvmProjectExtension> {
|
||||
sourceSets.getByName(sourceSet ?: "main") {
|
||||
dependencies(dependencyBlock)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.js") {
|
||||
project.configure<KotlinJsProjectExtension> {
|
||||
sourceSets.getByName(sourceSet ?: "main") {
|
||||
dependencies(dependencyBlock)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
sourceSets.getByName(sourceSet ?: "commonMain") {
|
||||
dependencies(dependencyBlock)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this module as an application module. JVM application should be enabled separately
|
||||
*/
|
||||
@ -212,38 +239,136 @@ public class KScienceNativeConfiguration {
|
||||
KScienceNativeTarget.iosArm64,
|
||||
).associateBy { it.preset }.toMutableMap()
|
||||
|
||||
public fun targets(vararg target: KScienceNativeTarget) {
|
||||
/**
|
||||
* Replace all targets
|
||||
*/
|
||||
public fun setTargets(vararg target: KScienceNativeTarget) {
|
||||
targets = target.associateBy { it.preset }.toMutableMap()
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a native target
|
||||
*/
|
||||
public fun target(target: KScienceNativeTarget) {
|
||||
targets[target.preset] = target
|
||||
}
|
||||
|
||||
public fun target(
|
||||
preset: KotlinNativePreset,
|
||||
targetName: String = preset.name,
|
||||
targetConfiguration: KotlinNativeTarget.() -> Unit = { },
|
||||
): Unit = target(KScienceNativeTarget(preset, targetName, targetConfiguration))
|
||||
}
|
||||
|
||||
public open class KScienceMppExtension(project: Project) : KScienceExtension(project) {
|
||||
internal var jvmConfiguration: ((KotlinJvmTarget) -> Unit)? = { }
|
||||
|
||||
/**
|
||||
* Custom configuration for JVM target. If null - disable JVM target
|
||||
*/
|
||||
public fun jvm(block: KotlinJvmTarget.() -> Unit) {
|
||||
jvmConfiguration = block
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
jvm(block)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal var jsConfiguration: ((KotlinJsTargetDsl) -> Unit)? = { }
|
||||
/**
|
||||
* Remove Jvm target
|
||||
*/
|
||||
public fun noJvm() {
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
targets.removeIf { it is KotlinJvmTarget }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom configuration for JS target. If null - disable JS target
|
||||
*/
|
||||
public fun js(block: KotlinJsTargetDsl.() -> Unit) {
|
||||
jsConfiguration = block
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
js(block)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal var nativeConfiguration: KScienceNativeConfiguration? = null
|
||||
public fun noJs() {
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
targets.removeIf { it is KotlinJsTargetDsl }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun native(block: KScienceNativeConfiguration.() -> Unit = {}) {
|
||||
nativeConfiguration = KScienceNativeConfiguration().apply(block)
|
||||
public fun native(block: KScienceNativeConfiguration.() -> Unit = {}): Unit = with(project) {
|
||||
val nativeConfiguration = KScienceNativeConfiguration().apply(block)
|
||||
pluginManager.withPlugin("space.kscience.gradle.mpp") {
|
||||
configure<KotlinMultiplatformExtension> {
|
||||
sourceSets {
|
||||
val nativeTargets: List<KotlinNativeTarget> =
|
||||
nativeConfiguration.targets.values.mapNotNull { nativeTarget ->
|
||||
when (nativeTarget.preset) {
|
||||
KotlinNativePreset.linuxX64 -> linuxX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
KotlinNativePreset.mingwX64 -> mingwX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
KotlinNativePreset.macosX64 -> macosX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
KotlinNativePreset.iosX64 -> iosX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
KotlinNativePreset.iosArm64 -> iosArm64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
// else -> {
|
||||
// logger.error("Native preset ${nativeTarget.preset} not recognised.")
|
||||
// null
|
||||
// }
|
||||
}
|
||||
}
|
||||
val commonMain by getting
|
||||
val commonTest by getting
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
|
||||
public open class KScienceJSPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project): Unit = project.run {
|
||||
@ -11,7 +10,6 @@ public open class KScienceJSPlugin : Plugin<Project> {
|
||||
} else {
|
||||
logger.info("Kotlin JS plugin is already present")
|
||||
}
|
||||
|
||||
apply<KScienceCommonPlugin>()
|
||||
project.configureKScience()
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,14 @@ package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
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"))
|
||||
if (!plugins.hasPlugin("org.jetbrains.kotlin.jvm")) {
|
||||
plugins.apply("org.jetbrains.kotlin.jvm")
|
||||
else
|
||||
} else {
|
||||
logger.info("Kotlin JVM plugin is already present")
|
||||
|
||||
apply<KScienceCommonPlugin>()
|
||||
}
|
||||
project.configureKScience()
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.hasPlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
||||
|
||||
@ -14,7 +13,6 @@ public open class KScienceMPPlugin : Plugin<Project> {
|
||||
} else {
|
||||
logger.info("Kotlin MPP plugin is already present")
|
||||
}
|
||||
|
||||
apply<KScienceCommonPlugin>()
|
||||
project.configureKScience()
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
|
||||
@Deprecated("Use common configuration block")
|
||||
public class KScienceNativePlugin : Plugin<Project> {
|
||||
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")
|
||||
}
|
||||
|
||||
if (!plugins.hasPlugin(KScienceCommonPlugin::class)) {
|
||||
logger.info("KScience plugin is not resolved. Adding it automatically")
|
||||
apply<KScienceCommonPlugin>()
|
||||
}
|
||||
|
||||
configure<KotlinMultiplatformExtension> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package space.kscience.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.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
|
||||
/**
|
||||
* Create a separate target for node
|
||||
*/
|
||||
public class KScienceNodePlugin : Plugin<Project> {
|
||||
override fun apply(target: Project): Unit = target.run {
|
||||
//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")
|
||||
plugins.apply("org.jetbrains.kotlin.multiplatform")
|
||||
}
|
||||
|
||||
if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
|
||||
logger.info("KScience plugin is not resolved. Adding it automatically")
|
||||
apply<KScienceCommonPlugin>()
|
||||
}
|
||||
|
||||
configure<KotlinMultiplatformExtension> {
|
||||
js(name = "node", compiler = IR) {
|
||||
nodejs()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val commonMain = findByName("commonMain")!!
|
||||
val commonTest = findByName("commonTest")!!
|
||||
|
||||
val jsCommonMain = create("jsCommonMain").apply {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
val jsCommonTest = create("jsCommonTest").apply {
|
||||
dependsOn(commonTest)
|
||||
}
|
||||
|
||||
findByName("jsMain")?.dependsOn(jsCommonMain)
|
||||
findByName("jsTest")?.dependsOn(jsCommonTest)
|
||||
|
||||
findByName("nodeMain")?.apply {
|
||||
dependsOn(jsCommonMain)
|
||||
dependencies {
|
||||
api("org.jetbrains.kotlinx:kotlinx-nodejs:${KScienceVersions.kotlinxNodeVersion}")
|
||||
}
|
||||
}
|
||||
findByName("nodeTest")?.dependsOn(jsCommonMain)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ import org.jetbrains.dokka.gradle.DokkaPlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import space.kscience.gradle.internal.applyRepos
|
||||
import space.kscience.gradle.internal.applySettings
|
||||
@ -44,7 +43,7 @@ public fun Project.configureKScience(
|
||||
|
||||
//Configuration for K-JVM plugin
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||
registerKScienceExtension(::KScienceExtension)
|
||||
val extension = registerKScienceExtension(::KScienceExtension)
|
||||
|
||||
//logger.info("Applying KScience configuration for JVM project")
|
||||
configure<KotlinJvmProjectExtension> {
|
||||
@ -78,7 +77,7 @@ public fun Project.configureKScience(
|
||||
}
|
||||
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
|
||||
registerKScienceExtension(::KScienceExtension)
|
||||
val extension = registerKScienceExtension(::KScienceExtension)
|
||||
|
||||
//logger.info("Applying KScience configuration for JS project")
|
||||
configure<KotlinJsProjectExtension> {
|
||||
@ -118,31 +117,25 @@ public fun Project.configureKScience(
|
||||
}
|
||||
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
val configuration = registerKScienceExtension(::KScienceMppExtension)
|
||||
val extension = registerKScienceExtension(::KScienceMppExtension)
|
||||
|
||||
configure<KotlinMultiplatformExtension> {
|
||||
configuration.jvmConfiguration?.let { jvmConfiguration ->
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
jvmTarget = KScienceVersions.JVM_TARGET.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs
|
||||
}
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
jvmTarget = KScienceVersions.JVM_TARGET.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs
|
||||
}
|
||||
jvmConfiguration(this)
|
||||
}
|
||||
}
|
||||
|
||||
configuration.jsConfiguration?.let { jsConfiguration ->
|
||||
js(IR) {
|
||||
browser {
|
||||
commonWebpackConfig {
|
||||
cssSupport {
|
||||
enabled = true
|
||||
}
|
||||
js(IR) {
|
||||
browser {
|
||||
commonWebpackConfig {
|
||||
cssSupport {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
jsConfiguration(this)
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,79 +151,17 @@ public fun Project.configureKScience(
|
||||
implementation(kotlin("test-annotations-common"))
|
||||
}
|
||||
}
|
||||
val jvmMain by getting
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-junit5"))
|
||||
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
|
||||
}
|
||||
}
|
||||
val jsMain by getting
|
||||
val jsTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-js"))
|
||||
}
|
||||
}
|
||||
|
||||
configuration.nativeConfiguration?.let { nativeConfiguration ->
|
||||
val nativeTargets: List<KotlinNativeTargetWithHostTests> =
|
||||
nativeConfiguration.targets.values.mapNotNull { nativeTarget ->
|
||||
when (nativeTarget.preset) {
|
||||
KotlinNativePreset.linuxX64 -> linuxX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
KotlinNativePreset.mingwX64 -> linuxX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
KotlinNativePreset.macosX64 -> linuxX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
KotlinNativePreset.iosX64 -> linuxX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
KotlinNativePreset.iosArm64 -> linuxX64(
|
||||
nativeTarget.targetName,
|
||||
nativeTarget.targetConfiguration
|
||||
)
|
||||
|
||||
else -> {
|
||||
logger.error("Native preset ${nativeTarget.preset} not recognised.")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.all {
|
||||
|
Loading…
Reference in New Issue
Block a user