diff --git a/README.adoc b/README.adoc index eaaf2a37..3c692b9a 100644 --- a/README.adoc +++ b/README.adoc @@ -195,9 +195,8 @@ It is possible a dependency on the `test` source set by setting property `includ == Using JMH Gradle Plugin with Shadow Plugin -Optionally it is possible to use the https://github.com/johnrengelman/shadow/[Shadow Plugin] (or the -https://github.com/Goooler/shadow[forked Shadow Plugin]) to do actual JMH jar creation. The configuration of -Shadow Plugin for JMH jar is done via `jmhJar` block. +Optionally it is possible to use the https://github.com/GradleUp/shadow[Shadow Plugin] to do actual JMH jar creation. +The configuration of Shadow Plugin for JMH jar is done via `jmhJar` block. For example: [source,groovy] diff --git a/build.gradle.kts b/build.gradle.kts index a46b97f6..032af4be 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,7 +38,7 @@ dependencies { exclude(mapOf("group" to "org.codehaus.groovy")) } pluginsUnderTest("gradle.plugin.com.github.johnrengelman:shadow:7.1.2") - pluginsUnderTest("io.github.goooler.shadow:shadow-gradle-plugin:8.1.8") + pluginsUnderTest("com.gradleup.shadow:shadow-gradle-plugin:8.3.0") testImplementation("org.openjdk.jmh:jmh-core:$jmhVersion") testImplementation("org.openjdk.jmh:jmh-generator-bytecode:$jmhVersion") diff --git a/src/funcTest/groovy/me/champeau/jmh/AbstractFuncSpec.groovy b/src/funcTest/groovy/me/champeau/jmh/AbstractFuncSpec.groovy index 4df83dd5..c0b5f0b4 100644 --- a/src/funcTest/groovy/me/champeau/jmh/AbstractFuncSpec.groovy +++ b/src/funcTest/groovy/me/champeau/jmh/AbstractFuncSpec.groovy @@ -30,15 +30,18 @@ abstract class AbstractFuncSpec extends Specification { GradleVersion.current() ] - protected static final List TESTED_SHADOW_PLUGINS = [ - 'com.github.johnrengelman.shadow', - 'io.github.goooler.shadow' + /** Plugin + min Gradle version the plugin supports. */ + protected static final Map TESTED_SHADOW_PLUGINS = [ + 'com.gradleup.shadow': GradleVersion.version('8.3'), + 'com.github.johnrengelman.shadow': GradleVersion.version('7.0') ] - protected static final Map TESTED_SHADOW_PLUGIN_FOLDERS = [ - 'com.github.johnrengelman.shadow': 'shadow', - 'io.github.goooler.shadow': 'forked-shadow' - ] + /** List of plugin + Gradle version combinations. */ + protected static final List> TESTED_SHADOW_GRADLE_COMBINATIONS = + TESTED_SHADOW_PLUGINS.collect { plugin, minGradle -> + TESTED_GRADLE_VERSIONS.findAll { gradle -> gradle >= minGradle } + .collect { gradle -> Tuple.tuple(plugin, gradle) } + }.collectMany { it } @TempDir File temporaryFolder @@ -51,12 +54,20 @@ abstract class AbstractFuncSpec extends Specification { testedGradleVersion = gradleVersion } - // TODO: We can remove this and fully enable CC in tests once bump the Shadow version to 8.1.1+. // TODO: But Kotlin test still fails, it was suppressed in 1bab41646df6f47aea84ea3febeeec1c76cd2e79, need to investigate. protected void withoutConfigurationCache(String reason) { noConfigurationCacheReason = reason } + /** + * TODO: remove this once we bumped min Shadow support to 8.1.1 or dropped it. + */ + protected void disableConfigCacheForShadow(String pluginId) { + if (pluginId == 'com.github.johnrengelman.shadow') { + noConfigurationCacheReason = 'com.github.johnrengelman.shadow supports CC from 8.1.1+' + } + } + File getProjectDir() { temporaryFolder } @@ -73,9 +84,10 @@ abstract class AbstractFuncSpec extends Specification { file("build/reports/benchmarks.csv") } - protected void usingSample(String name) { + protected File usingSample(String name) { File sampleDir = new File("src/funcTest/resources/$name") FileUtils.copyDirectory(sampleDir, projectDir) + return projectDir } protected File file(String path) { diff --git a/src/funcTest/groovy/me/champeau/jmh/JmhWithShadowPluginSpec.groovy b/src/funcTest/groovy/me/champeau/jmh/JmhWithShadowPluginSpec.groovy index 187601b5..df2b7c3c 100644 --- a/src/funcTest/groovy/me/champeau/jmh/JmhWithShadowPluginSpec.groovy +++ b/src/funcTest/groovy/me/champeau/jmh/JmhWithShadowPluginSpec.groovy @@ -25,9 +25,13 @@ class JmhWithShadowPluginSpec extends AbstractFuncSpec { def "Run #language benchmarks that are packaged with Shadow plugin (#gradleVersion #language #shadowPlugin)"() { given: - usingSample("${language.toLowerCase()}-${TESTED_SHADOW_PLUGIN_FOLDERS[shadowPlugin]}-project") + def projectRoot = usingSample("${language.toLowerCase()}-shadow-project") + def rootBuildFile = new File(projectRoot, 'build.gradle') + def buildFileContent = rootBuildFile.text.replace("shadowPlugin", shadowPlugin) + rootBuildFile.text = buildFileContent + usingGradleVersion(gradleVersion) - withoutConfigurationCache('shadow plugin unsupported') + disableConfigCacheForShadow(shadowPlugin) when: def result = build("jmh") @@ -39,8 +43,10 @@ class JmhWithShadowPluginSpec extends AbstractFuncSpec { where: [language, gradleVersion, shadowPlugin] << [ ['Java', 'Scala'], - TESTED_GRADLE_VERSIONS, - TESTED_SHADOW_PLUGINS - ].combinations() + TESTED_SHADOW_GRADLE_COMBINATIONS, + ].combinations { lang, tuple -> + def (plugin, gradle) = tuple + [lang, gradle, plugin] + } } } diff --git a/src/funcTest/groovy/me/champeau/jmh/ProjectWithDuplicateClassesSpec.groovy b/src/funcTest/groovy/me/champeau/jmh/ProjectWithDuplicateClassesSpec.groovy index 49e6af69..4df974d6 100644 --- a/src/funcTest/groovy/me/champeau/jmh/ProjectWithDuplicateClassesSpec.groovy +++ b/src/funcTest/groovy/me/champeau/jmh/ProjectWithDuplicateClassesSpec.groovy @@ -63,7 +63,7 @@ class ProjectWithDuplicateClassesSpec extends AbstractFuncSpec { given: usingGradleVersion(gradleVersion) - withoutConfigurationCache('shadow plugin unsupported') + disableConfigCacheForShadow(shadowPlugin) and: buildFile << """ @@ -89,10 +89,7 @@ class ProjectWithDuplicateClassesSpec extends AbstractFuncSpec { result.task(":jmhJar").outcome == FAILED where: - [shadowPlugin, gradleVersion] << [ - TESTED_SHADOW_PLUGINS, - TESTED_GRADLE_VERSIONS - ].combinations() + [shadowPlugin, gradleVersion] << TESTED_SHADOW_GRADLE_COMBINATIONS } def "Show warning for duplicate classes when DuplicatesStrategy.WARN is used (#gradleVersion)"() { @@ -131,7 +128,7 @@ class ProjectWithDuplicateClassesSpec extends AbstractFuncSpec { given: usingGradleVersion(gradleVersion) - withoutConfigurationCache('shadow plugin unsupported') + disableConfigCacheForShadow(shadowPlugin) and: buildFile << """ @@ -158,10 +155,7 @@ class ProjectWithDuplicateClassesSpec extends AbstractFuncSpec { assertDuplicateClassesWarning(gradleVersion, result.output) where: - [shadowPlugin, gradleVersion] << [ - TESTED_SHADOW_PLUGINS, - TESTED_GRADLE_VERSIONS - ].combinations() + [shadowPlugin, gradleVersion] << TESTED_SHADOW_GRADLE_COMBINATIONS } private static boolean assertDuplicateClassesWarning(GradleVersion gradleVersion, String output) { diff --git a/src/funcTest/groovy/me/champeau/jmh/ProjectWithDuplicateDependenciesSpec.groovy b/src/funcTest/groovy/me/champeau/jmh/ProjectWithDuplicateDependenciesSpec.groovy index 4ac4c62a..4daeeb36 100644 --- a/src/funcTest/groovy/me/champeau/jmh/ProjectWithDuplicateDependenciesSpec.groovy +++ b/src/funcTest/groovy/me/champeau/jmh/ProjectWithDuplicateDependenciesSpec.groovy @@ -54,7 +54,7 @@ class ProjectWithDuplicateDependenciesSpec extends AbstractFuncSpec { given: usingGradleVersion(gradleVersion) - withoutConfigurationCache('shadow plugin unsupported') + disableConfigCacheForShadow(shadowPlugin) and: createBuildFile(""" @@ -73,10 +73,7 @@ class ProjectWithDuplicateDependenciesSpec extends AbstractFuncSpec { benchmarksCsv.text.contains('JavaBenchmark.sqrtBenchmark') where: - [shadowPlugin, gradleVersion] << [ - TESTED_SHADOW_PLUGINS, - TESTED_GRADLE_VERSIONS - ].combinations() + [shadowPlugin, gradleVersion] << TESTED_SHADOW_GRADLE_COMBINATIONS } void createBuildFile(String plugins) { diff --git a/src/funcTest/resources/java-forked-shadow-project/build.gradle b/src/funcTest/resources/java-forked-shadow-project/build.gradle deleted file mode 100644 index da1e0b0f..00000000 --- a/src/funcTest/resources/java-forked-shadow-project/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2014-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -plugins { - id 'java' - id 'io.github.goooler.shadow' - id 'me.champeau.jmh' -} - -repositories { - mavenCentral() -} - -jmh { - resultFormat = 'csv' - resultsFile = file('build/reports/benchmarks.csv') -} diff --git a/src/funcTest/resources/java-forked-shadow-project/settings.gradle b/src/funcTest/resources/java-forked-shadow-project/settings.gradle deleted file mode 100644 index 0407eef9..00000000 --- a/src/funcTest/resources/java-forked-shadow-project/settings.gradle +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2014-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -rootProject.name = "java-forked-shadow-project" \ No newline at end of file diff --git a/src/funcTest/resources/java-forked-shadow-project/src/jmh/java/me/champeau/gradle/jmh/mixlang/JavaBenchmark.java b/src/funcTest/resources/java-forked-shadow-project/src/jmh/java/me/champeau/gradle/jmh/mixlang/JavaBenchmark.java deleted file mode 100644 index 58873655..00000000 --- a/src/funcTest/resources/java-forked-shadow-project/src/jmh/java/me/champeau/gradle/jmh/mixlang/JavaBenchmark.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2014-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package me.champeau.jmh.mixlang; - -import org.openjdk.jmh.annotations.*; - -@State(Scope.Benchmark) -@Fork(1) -@Warmup(iterations = 0) -@Measurement(iterations = 1) -public class JavaBenchmark { - private double value; - - @Setup - public void setUp() { - value = 3.0; - } - - @Benchmark - public double sqrtBenchmark(){ - return Math.sqrt(value); - } -} diff --git a/src/funcTest/resources/java-project-with-feature-previews/build.gradle b/src/funcTest/resources/java-project-with-feature-previews/build.gradle index 23728d4b..01bff374 100644 --- a/src/funcTest/resources/java-project-with-feature-previews/build.gradle +++ b/src/funcTest/resources/java-project-with-feature-previews/build.gradle @@ -25,16 +25,18 @@ repositories { // Configure Java compilation tasks to enable feature previews tasks.withType(JavaCompile).configureEach { options.compilerArgs.add("--enable-preview") + options.release = 22 javaCompiler.set(javaToolchains.compilerFor { - // Using 15 so that we can try a feature preview - languageVersion.set(JavaLanguageVersion.of(15)) + // Using 22 so that we can try a feature preview, because + // --enable-preview does not work with 21. + languageVersion.set(JavaLanguageVersion.of(22)) }) } -// Then configure the JMH Tasks to build with Java 15 +// Then configure the JMH Tasks to build with Java 22 tasks.withType(me.champeau.jmh.WithJavaToolchain).configureEach { javaLauncher.set(javaToolchains.launcherFor { - languageVersion.set(JavaLanguageVersion.of(15)) + languageVersion.set(JavaLanguageVersion.of(22)) }) } diff --git a/src/funcTest/resources/java-shadow-project/build.gradle b/src/funcTest/resources/java-shadow-project/build.gradle index a6aa3341..4fdb6794 100644 --- a/src/funcTest/resources/java-shadow-project/build.gradle +++ b/src/funcTest/resources/java-shadow-project/build.gradle @@ -15,7 +15,7 @@ */ plugins { id 'java' - id 'com.github.johnrengelman.shadow' + id 'shadowPlugin' id 'me.champeau.jmh' } @@ -26,4 +26,4 @@ repositories { jmh { resultFormat = 'csv' resultsFile = file('build/reports/benchmarks.csv') -} \ No newline at end of file +} diff --git a/src/funcTest/resources/scala-forked-shadow-project/build.gradle b/src/funcTest/resources/scala-forked-shadow-project/build.gradle deleted file mode 100644 index a835fa5b..00000000 --- a/src/funcTest/resources/scala-forked-shadow-project/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2014-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -plugins { - id 'scala' - id 'io.github.goooler.shadow' - id 'me.champeau.jmh' -} - -repositories { - mavenCentral() -} - -dependencies { - implementation 'org.scala-lang:scala-library:2.13.14' -} - -jmh { - resultFormat = 'csv' - resultsFile = file('build/reports/benchmarks.csv') -} \ No newline at end of file diff --git a/src/funcTest/resources/scala-forked-shadow-project/settings.gradle b/src/funcTest/resources/scala-forked-shadow-project/settings.gradle deleted file mode 100644 index a7c5b5fc..00000000 --- a/src/funcTest/resources/scala-forked-shadow-project/settings.gradle +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2014-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -rootProject.name = "scala-forked-shadow-project" \ No newline at end of file diff --git a/src/funcTest/resources/scala-forked-shadow-project/src/jmh/scala/me/champeau/gradle/jmh/mixlang/ScalaBenchmark.scala b/src/funcTest/resources/scala-forked-shadow-project/src/jmh/scala/me/champeau/gradle/jmh/mixlang/ScalaBenchmark.scala deleted file mode 100644 index a6dc7b88..00000000 --- a/src/funcTest/resources/scala-forked-shadow-project/src/jmh/scala/me/champeau/gradle/jmh/mixlang/ScalaBenchmark.scala +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2014-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package me.champeau.jmh.mixlang - -import org.openjdk.jmh.annotations._ - -@State(Scope.Benchmark) -@Fork(1) -@Warmup(iterations = 0) -@Measurement(iterations = 1) -class ScalaBenchmark { - var value: Double = 0 - - @Setup - def setUp(): Unit = { - value = 3.0 - } - - @Benchmark - def sqrtBenchmark(): Double = { - return Math.sqrt(value) - } - -} diff --git a/src/funcTest/resources/scala-shadow-project/build.gradle b/src/funcTest/resources/scala-shadow-project/build.gradle index 22002eee..9226c0d3 100644 --- a/src/funcTest/resources/scala-shadow-project/build.gradle +++ b/src/funcTest/resources/scala-shadow-project/build.gradle @@ -15,7 +15,7 @@ */ plugins { id 'scala' - id 'com.github.johnrengelman.shadow' + id 'shadowPlugin' id 'me.champeau.jmh' } diff --git a/src/funcTest/resources/scala-shadow-project/settings.gradle b/src/funcTest/resources/scala-shadow-project/settings.gradle index 9c8631c9..a7c5b5fc 100644 --- a/src/funcTest/resources/scala-shadow-project/settings.gradle +++ b/src/funcTest/resources/scala-shadow-project/settings.gradle @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -rootProject.name = "scala-shadow-project" \ No newline at end of file +rootProject.name = "scala-forked-shadow-project" \ No newline at end of file diff --git a/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy b/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy index b99f3369..7fe14a7e 100644 --- a/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy +++ b/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy @@ -64,7 +64,7 @@ class JMHPlugin implements Plugin { dependencyHandler.addProvider(JMH_NAME, project.providers.provider { "${JMH_CORE_DEPENDENCY}${extension.jmhVersion.get()}" }) {} dependencyHandler.addProvider(JMH_NAME, project.providers.provider { "${JMH_GENERATOR_DEPENDENCY}${extension.jmhVersion.get()}" }) {} - def hasShadow = project.plugins.findPlugin('com.github.johnrengelman.shadow') != null || project.plugins.findPlugin('io.github.goooler.shadow') != null + def hasShadow = project.plugins.findPlugin('com.gradleup.shadow') != null || project.plugins.findPlugin('com.github.johnrengelman.shadow') != null createJmhSourceSet(project) final Configuration runtimeConfiguration = configureJmhRuntimeClasspathConfiguration(project, extension) diff --git a/src/test/groovy/me/champeau/jmh/JMHPluginTest.groovy b/src/test/groovy/me/champeau/jmh/JMHPluginTest.groovy index 47f3e3b0..0f2e3019 100644 --- a/src/test/groovy/me/champeau/jmh/JMHPluginTest.groovy +++ b/src/test/groovy/me/champeau/jmh/JMHPluginTest.groovy @@ -118,8 +118,8 @@ class JMHPluginTest extends Specification { where: shadowPlugin << [ - 'com.github.johnrengelman.shadow', - 'io.github.goooler.shadow' + 'com.gradleup.shadow', + 'com.github.johnrengelman.shadow' ] }