diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f2d4ba..23ff5d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Easier dependency handling in `kscience` block +- Customizable base jdk version ### Changed - MPP does not use JVM and JS(IR) targets anymore. They could be turned manually via `js()`, `jvm()` or `fullStack()` diff --git a/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt b/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt index 6ae3c2d..e0aa6bf 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceExtension.kt @@ -3,8 +3,10 @@ package space.kscience.gradle import org.gradle.api.Project import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.plugins.ApplicationPlugin +import org.gradle.api.provider.Property import org.gradle.api.tasks.Copy import org.gradle.api.tasks.testing.Test +import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.kotlin.dsl.* import org.gradle.language.jvm.tasks.ProcessResources import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension @@ -44,8 +46,17 @@ public val Project.isInDevelopment: Boolean || version.toString().endsWith("SNAPSHOT") + +private const val defaultJdkVersion = 11 + public open class KScienceExtension(public val project: Project) { + public val jdkVersionProperty: Property = project.objects.property().apply { + set(defaultJdkVersion) + } + + public var jdkVersion: Int by jdkVersionProperty + /** * Use coroutines-core with default version or [version] */ @@ -337,7 +348,7 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro } } jvmToolchain { - languageVersion.set(KScienceVersions.JVM_TARGET) + languageVersion.set(jdkVersionProperty.map { JavaLanguageVersion.of(it) }) } } project.tasks.withType { diff --git a/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt index 063685a..168297b 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceJVMPlugin.kt @@ -3,6 +3,7 @@ package space.kscience.gradle import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.tasks.testing.Test +import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.get @@ -20,7 +21,7 @@ public open class KScienceJVMPlugin : Plugin { } else { logger.info("Kotlin JVM plugin is already present") } - registerKScienceExtension(::KScienceExtension) + val extension = registerKScienceExtension(::KScienceExtension) //logger.info("Applying KScience configuration for JVM project") configure { @@ -37,7 +38,7 @@ public open class KScienceJVMPlugin : Plugin { if (explicitApi == null) explicitApiWarning() jvmToolchain { - languageVersion.set(KScienceVersions.JVM_TARGET) + languageVersion.set(extension.jdkVersionProperty.map { JavaLanguageVersion.of(it) }) } } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceVersions.kt b/src/main/kotlin/space/kscience/gradle/KScienceVersions.kt index a70d28f..c9009d3 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceVersions.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceVersions.kt @@ -1,7 +1,6 @@ package space.kscience.gradle -import org.gradle.jvm.toolchain.JavaLanguageVersion import org.tomlj.Toml /** @@ -24,8 +23,6 @@ public object KScienceVersions { public val jsBom: String get() = toml.getString("versions.jsBom")!! internal val junit: String get() = toml.getString("versions.junit")!! - public val JVM_TARGET: JavaLanguageVersion = JavaLanguageVersion.of(11) - public object Serialization { public val xmlVersion: String get() = toml.getString("versions.xmlutil")!! public val yamlKtVersion: String get() = toml.getString("versions.yamlkt")!!