Skip to content

Commit

Permalink
Setup jvm toolchain
Browse files Browse the repository at this point in the history
* compile using JDK 8
* able to run tests on JDK 8, 11 and 17
  • Loading branch information
olme04 committed Jan 12, 2022
1 parent e76d8f5 commit 9c94b59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ dependencies {
implementation(buildLibs.build.kotlin)
implementation(buildLibs.build.kotlinx.atomicfu)
}

kotlin {
jvmToolchain {
this as JavaToolchainSpec
languageVersion.set(JavaLanguageVersion.of(8))
}
}
16 changes: 16 additions & 0 deletions buildSrc/src/main/kotlin/targetsJvm.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import org.gradle.jvm.toolchain.*
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.*

fun KotlinMultiplatformExtension.configureJvm(block: TargetBuilder.() -> Unit = {}) {
jvmToolchain { (this as JavaToolchainSpec).setJdk(8) }
jvm {
listOf(11, 17).forEach { jdkVersion ->
testRuns.create("${jdkVersion}Test") {
executionTask.configure {
javaLauncher.set(
project.extensions.getByType<JavaToolchainService>().launcherFor { setJdk(11) }
)
}
}
}
testRuns.all {
executionTask.configure {
// ActiveProcessorCount is used here, to make sure local setup is similar as on CI
Expand All @@ -12,3 +24,7 @@ fun KotlinMultiplatformExtension.configureJvm(block: TargetBuilder.() -> Unit =
}
TargetBuilder(sourceSets, "jvm").block()
}

private fun JavaToolchainSpec.setJdk(version: Int) {
languageVersion.set(JavaLanguageVersion.of(version))
}

0 comments on commit 9c94b59

Please sign in to comment.