melix / jmh-gradle-plugin

Integrates the JMH benchmarking framework with Gradle
Apache License 2.0
662 stars 88 forks source link

Kotlin internal APIs unable to be used from JMH out of the box #197

Closed MariusVolkhart closed 2 years ago

MariusVolkhart commented 3 years ago

Describe the bug Kotlin has the concept of internal code - code which is only accessible to the current "module". When running JMH benchmarks, I believe most developers would consider their benchmarks to be part of the same module. Right now, the JMH plugin does not resolve internal APIs from the main sourceset to the jmh sourceset.

To Reproduce Steps to reproduce the behavior: See #196 for a reproduce of the issue.

Work around Modifying the Gradle build file a bit, one is able to work around the problem.

kotlin.target.compilations.getByName("jmh") {
    associateWith(target.compilations.getByName("main"))
}

This behavior is similar to what the current recommendation is when using the test-fixtures plugin with Kotlin.

Note that in my local testing, Gradle compilation and execution will succeed with this workaround, but IntelliJ IDEA still reports errors in the editor.

Desired behavior Ideally, the JMH plugin would detect that Kotlin is in use, and automatically associate the jmh sourceset with the main sourceset.