Customizeable jdk version

This commit is contained in:
Alexander Nozik 2023-02-12 11:32:46 +03:00
parent 4bfd042f96
commit 1e3018275d
4 changed files with 16 additions and 6 deletions

View File

@ -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()`

View File

@ -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<Int> = project.objects.property<Int>().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<Test> {

View File

@ -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<Project> {
} else {
logger.info("Kotlin JVM plugin is already present")
}
registerKScienceExtension(::KScienceExtension)
val extension = registerKScienceExtension(::KScienceExtension)
//logger.info("Applying KScience configuration for JVM project")
configure<KotlinJvmProjectExtension> {
@ -37,7 +38,7 @@ public open class KScienceJVMPlugin : Plugin<Project> {
if (explicitApi == null) explicitApiWarning()
jvmToolchain {
languageVersion.set(KScienceVersions.JVM_TARGET)
languageVersion.set(extension.jdkVersionProperty.map { JavaLanguageVersion.of(it) })
}
}

View File

@ -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")!!