Easier dependency handling for kscience

This commit is contained in:
Alexander Nozik 2023-02-03 19:28:29 +03:00
parent a78a4f6118
commit 1b179e0b05

View File

@ -128,28 +128,18 @@ public open class KScienceExtension(public val project: Project) {
} }
} }
public fun jvmDependencies(dependencyBlock: KotlinDependencyHandler.() -> Unit) { public fun testDependencies(sourceSet: String? = null, dependencyBlock: KotlinDependencyHandler.() -> Unit) {
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
project.configure<KotlinJvmProjectExtension> { project.configure<KotlinJvmProjectExtension> {
sourceSets.getByName("main") { sourceSets.getByName(sourceSet ?: "test") {
dependencies(dependencyBlock) dependencies(dependencyBlock)
} }
} }
} }
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
project.configure<KotlinMultiplatformExtension> {
sourceSets.getByName("jvmMain") {
dependencies(dependencyBlock)
}
}
}
}
public fun jsDependencies(dependencyBlock: KotlinDependencyHandler.() -> Unit) {
project.pluginManager.withPlugin("org.jetbrains.kotlin.js") { project.pluginManager.withPlugin("org.jetbrains.kotlin.js") {
project.configure<KotlinJsProjectExtension> { project.configure<KotlinJsProjectExtension> {
sourceSets.getByName("main") { sourceSets.getByName(sourceSet ?: "test") {
dependencies(dependencyBlock) dependencies(dependencyBlock)
} }
} }
@ -157,13 +147,22 @@ public open class KScienceExtension(public val project: Project) {
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
project.configure<KotlinMultiplatformExtension> { project.configure<KotlinMultiplatformExtension> {
sourceSets.getByName("jsMain") { sourceSets.getByName(sourceSet ?: "commonTest") {
dependencies(dependencyBlock) dependencies(dependencyBlock)
} }
} }
} }
} }
public class DefaultSourceSet(public val key: String)
public fun dependencies(
defaultSourceSet: DefaultSourceSet,
dependencyBlock: KotlinDependencyHandler.() -> Unit,
): Unit = dependencies(defaultSourceSet.key, dependencyBlock)
/** /**
* Mark this module as an application module. JVM application should be enabled separately * Mark this module as an application module. JVM application should be enabled separately
*/ */
@ -196,15 +195,21 @@ public open class KScienceExtension(public val project: Project) {
/** /**
* Add context receivers to this project and all subprojects * Add context receivers to this project and all subprojects
*/ */
public fun withContextReceivers() { public fun useContextReceivers() {
project.allprojects { project.tasks.withType<KotlinCompile> {
tasks.withType<KotlinCompile> { kotlinOptions {
kotlinOptions { freeCompilerArgs = freeCompilerArgs + "-Xcontext-receivers"
freeCompilerArgs = freeCompilerArgs + "-Xcontext-receivers"
}
} }
} }
} }
public val jvmMain: DefaultSourceSet get() = DefaultSourceSet("jvmMain")
public val jvmTest: DefaultSourceSet get() = DefaultSourceSet("jvmTest")
public val jsMain: DefaultSourceSet get() = DefaultSourceSet("jsMain")
public val jsTest: DefaultSourceSet get() = DefaultSourceSet("jsTest")
public val nativeMain: DefaultSourceSet get() = DefaultSourceSet("nativeMain")
public val nativeTest: DefaultSourceSet get() = DefaultSourceSet("nativeTest")
} }
public enum class KotlinNativePreset { public enum class KotlinNativePreset {
@ -287,11 +292,6 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}") implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
} }
} }
getByName("jvmTest") {
dependencies {
implementation(kotlin("test-js"))
}
}
} }
jvmToolchain { jvmToolchain {
languageVersion.set(KScienceVersions.JVM_TARGET) languageVersion.set(KScienceVersions.JVM_TARGET)