Skip to content

Commit cd920c2

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
Use jvmToolchain(8) for the plugin and runtime
Otherwise, if the project using kotlinx-benchmark is configured with an older jvmToolchain than the Java with which Gradle was launched to assemble plugin or runtime, the following error occurs: Execution failed for task ':jvmBenchmarkGenerate'. > There was a failure while executing work items > A failure occurred while executing kotlinx.benchmark.gradle.JmhBytecodeGeneratorWorker > kotlinx/benchmark/gradle/JmhBytecodeGeneratorWorkParameters has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0 Similar issue: #176
1 parent 84d7d0f commit cd920c2

File tree

10 files changed

+48
-4
lines changed

10 files changed

+48
-4
lines changed

integration/src/test/kotlin/kotlinx/benchmark/integration/JvmToolchainsTest.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ import kotlin.test.assertEquals
66

77
class JvmToolchainsTest : GradleTest() {
88
@Test
9-
fun testJvmToolchainSetup() {
10-
val runner = project("kmp-with-toolchain", true, GradleTestVersion.v8_0) {
9+
fun testHigherVersionThanInGradle() {
10+
val runner = project("kmp-with-toolchain/higher-version-than-in-gradle", true, GradleTestVersion.v8_0)
11+
runner.runAndSucceed("benchmark") {
12+
assertEquals(TaskOutcome.SUCCESS, task(":jvmBenchmark")!!.outcome)
13+
assertOutputDoesNotContain("<failure>")
1114
}
15+
}
16+
17+
@Test
18+
fun testMinSupportedVersion() {
19+
val runner = project("kmp-with-toolchain/min-supported-version", true)
1220
runner.runAndSucceed("benchmark") {
1321
assertEquals(TaskOutcome.SUCCESS, task(":jvmBenchmark")!!.outcome)
1422
assertOutputDoesNotContain("<failure>")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
kotlin {
2+
jvmToolchain(8)
3+
jvm {}
4+
5+
sourceSets {
6+
commonMain {
7+
dependencies {
8+
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.5.0-SNAPSHOT")
9+
}
10+
}
11+
}
12+
}
13+
14+
benchmark {
15+
targets {
16+
register("jvm")
17+
}
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test
2+
3+
import kotlinx.benchmark.*
4+
import kotlin.math.*
5+
6+
// Don't really need to measure anything here, just check that the benchmark works
7+
@State(Scope.Benchmark)
8+
@Warmup(iterations = 0)
9+
@Measurement(iterations = 1, time = 100, timeUnit = BenchmarkTimeUnit.MILLISECONDS)
10+
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS)
11+
@BenchmarkMode(Mode.Throughput)
12+
open class CommonBenchmark {
13+
@Benchmark
14+
open fun mathBenchmark() = 3.14
15+
}

plugin/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ sourceSets {
8686
}
8787

8888
kotlin {
89+
jvmToolchain(8)
90+
8991
@OptIn(ExperimentalBuildToolsApi::class, ExperimentalKotlinGradlePluginApi::class)
9092
compilerVersion = libs.versions.kotlin.`for`.gradle.plugin.get()
91-
}
9293

93-
tasks.compileKotlin {
9494
compilerOptions {
9595
optIn.addAll(
9696
"kotlinx.benchmark.gradle.internal.KotlinxBenchmarkPluginInternalApi",

runtime/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ repositories {
1212
}
1313

1414
kotlin {
15+
jvmToolchain(8)
16+
1517
// According to https://kotlinlang.org/docs/native-target-support.html
1618

1719
// Tier 1

0 commit comments

Comments
 (0)