Skip to content

Commit e6a518c

Browse files
authored
Updated default JMH version to 1.37 and added its validation (#312)
If a project explicitly uses an older JMH version, the plugin will warn about it. If there are multiple JVM targets configured with different JMH versions, the plugin will warn about an unsupported setup. Closes #147
1 parent 84557fa commit e6a518c

File tree

15 files changed

+103
-13
lines changed

15 files changed

+103
-13
lines changed

docs/configuration-options.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,29 @@ benchmark {
8484
- **"definedByJmh"** – Let JMH determine the amount, using the value in the [`@Fork` annotation](https://javadoc.io/doc/org.openjdk.jmh/jmh-core/latest/org/openjdk/jmh/annotations/Fork.html) for the benchmark function or its enclosing class. If not specified by `@Fork`, it defaults to [Defaults.MEASUREMENT_FORKS (`5`)](https://javadoc.io/doc/org.openjdk.jmh/jmh-core/latest/org/openjdk/jmh/runner/Defaults.html#MEASUREMENT_FORKS).
8585

8686
The library offers the flexibility to specify the version of the Java Microbenchmark Harness (JMH) to use when running benchmarks on the JVM.
87-
The default version is set to `1.21`, but you can customize it while registering a JVM target for benchmarking:
87+
The default version is set to `1.37`, but you can customize it while registering a JVM target for benchmarking:
8888

8989
```kotlin
9090
benchmark {
9191
targets {
9292
register("jvmBenchmarks") {
9393
this as JvmBenchmarkTarget
94-
jmhVersion = "1.36"
94+
jmhVersion = "1.38"
9595
}
9696
}
9797
}
9898
```
9999

100100
Alternatively, you can utilize the project property `benchmarks_jmh_version` to achieve the same effect.
101101

102+
> [!WARNING]
103+
> While it is possible to register multiple JVM benchmark targets with different JMH versions,
104+
> such configurations are not supported. Using such configurations may result in runtime errors.
105+
106+
> [!NOTE]
107+
> It is recommended to change JMH version only when a new JMH version was released,
108+
> but `kotlinx-benchmark` plugin applied to a project is still using an older version.
109+
102110
### Kotlin/JS & Kotlin/Wasm
103111
| Option | Description | Possible Values | Default Value |
104112
|-----------------------------------------------|-------------------------------------------------------------------------------------------------------|-----------------|---------------|

examples/java/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ benchmark {
2525
targets {
2626
register("main") {
2727
this as JvmBenchmarkTarget
28-
jmhVersion = "1.21"
28+
jmhVersion = "1.37"
2929
}
3030
}
3131
}

examples/kotlin-jvm-separate-benchmark-source-set/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ benchmark {
4343
targets {
4444
register("benchmarks") {
4545
if (this is JvmBenchmarkTarget) {
46-
jmhVersion = "1.21"
46+
jmhVersion = "1.37"
4747
}
4848
}
4949
}

examples/kotlin-jvm/build.gradle.kts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ benchmark {
3636
}
3737
}
3838
targets {
39-
register("main") {
40-
this as JvmBenchmarkTarget
41-
jmhVersion = "1.21"
42-
}
39+
register("main")
4340
}
44-
}
41+
}

examples/kotlin-multiplatform/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ benchmark {
103103
// This one matches target name, e.g. 'jvm', 'js',
104104
// and registers its 'main' compilation, so 'jvm' registers 'jvmMain'
105105
register("jvm") {
106-
jmhVersion = "1.21"
106+
jmhVersion = "1.37"
107107
}
108108
// This one matches source set name, e.g. 'jvmMain', 'jvmTest', etc
109109
// and register the corresponding compilation (here the 'benchmark' compilation declared in the 'jvm' target)
110110
register("jvmBenchmark") {
111-
jmhVersion = "1.21"
111+
jmhVersion = "1.37"
112112
}
113113
register("jsDefaultExecutor")
114114
register("jsBuiltInExecutor") {

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ kotlin-for-gradle-plugin = "2.0.20" # Kotlin 2.1 removes support for the used la
66
kotlinx-binaryCompatibilityValidator = "0.16.2"
77
kotlinx-teamInfra = "0.4.0-dev-85"
88
squareup-kotlinpoet = "1.3.0"
9-
jmh = "1.21"
9+
jmh = "1.37"
1010
gradle-pluginPublish = "0.21.0"
1111

1212
# Note: This version can be overridden by passing `-Pmin_supported_gradle_version=<version>`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package kotlinx.benchmark.integration
2+
3+
import kotlin.test.Test
4+
5+
class JmhVersionValidationTest : GradleTest() {
6+
@Test
7+
fun verifyWarningsAboutJmhVersions() {
8+
val runner = project("conflicting-jmh-versions", true) {}
9+
10+
runner.runAndSucceed("assembleBenchmarks") {
11+
assertOutputContains("configures several JVM benchmarking targets that use different " +
12+
"JMH versions (1.21 is used by jvmFirst; 1.22 is used by jvmSecond, jvmThird). " +
13+
"Such configuration is not supported and may lead to runtime errors. " +
14+
"Consider using the same JMH version across all benchmarking targets.")
15+
assertOutputContains("Configured JMH version (1.22) is older than a default version supplied by the benchmarking plugin")
16+
assertOutputContains("Configured JMH version (1.21) is older than a default version supplied by the benchmarking plugin")
17+
}
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
kotlin {
2+
jvm {
3+
compilations.create('first') { associateWith(compilations.main) }
4+
compilations.create('second') { associateWith(compilations.main) }
5+
compilations.create('third') { associateWith(compilations.main) }
6+
}
7+
}
8+
9+
benchmark {
10+
targets {
11+
register("jvmFirst") { jmhVersion = "1.21" }
12+
register("jvmSecond") { jmhVersion = "1.22" }
13+
register("jvmThird") { jmhVersion = "1.22" }
14+
}
15+
}
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

plugin/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ val generatePluginConstants by tasks.registering {
141141
val kotlinCompilerVersion = libs.versions.kotlin.asProvider()
142142
inputs.property("kotlinCompilerVersion", kotlinCompilerVersion)
143143

144+
val defaultJvmVersion = libs.versions.jmh
145+
inputs.property("defaultJmhVersion", defaultJvmVersion)
146+
144147
doLast {
145148
constantsKtFile.writeText(
146149
"""|package kotlinx.benchmark.gradle.internal
@@ -150,6 +153,7 @@ val generatePluginConstants by tasks.registering {
150153
| const val MIN_SUPPORTED_GRADLE_VERSION = "${minSupportedGradleVersion.get()}"
151154
| const val MIN_SUPPORTED_KOTLIN_VERSION = "${minSupportedKotlinVersion.get()}"
152155
| const val DEFAULT_KOTLIN_COMPILER_VERSION = "${kotlinCompilerVersion.get()}"
156+
| const val DEFAULT_JMH_VERSION = "${defaultJvmVersion.get()}"
153157
|}
154158
|""".trimMargin()
155159
)

0 commit comments

Comments
 (0)