melix / jmh-gradle-plugin

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

Plugin doesn't work with mrjars #225

Open Sineaggi opened 1 year ago

Sineaggi commented 1 year ago

Describe the bug The jmhJar task is currently unaware of mrjars. If you have a dependency on an mrjar, or you use the me.champeau.mrjar plugin, the jmhJar task does not include the Multi-Release attribute.

To Reproduce Steps to reproduce the behavior:

  1. Use mr jar
  2. Change e.g. java toolchain jmh was run with
  3. Observe no change in classes loaded

Requires mrjar dependency when testing compatibility with mrjar plugin

dependencies {
    "pluginsUnderTest"("me.champeau.gradle.mrjar:plugin:0.1.1")
}

Test can be added to JMHPluginTest.groovy

    void "manifest includes multi release attribute"() {
        when:
        Project project = ProjectBuilder.builder().build()
        project.repositories {
            mavenCentral()
        }
        project.apply plugin: 'java'
        project.apply plugin: 'me.champeau.jmh'
        project.apply plugin: 'me.champeau.mrjar'

        project.multiRelease {
            targetVersions(8, 17)
        }

        then:
        // regular jar task contains 'Multi-Release' attribute
        def jar = project.tasks.findByName('jar')
        'Multi-Release' in jar.manifest.attributes

        // jmhJar task does not contain 'Multi-Release' attribute
        def task = project.tasks.findByName('jmhJar')
        'Multi-Release' in task.manifest.attributes
    }

A proper fix might also need to look through the manifests of other jars for Multi-Release attribute.