Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support com.gradleup.shadow plugin #267

Merged
merged 18 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
30 changes: 21 additions & 9 deletions src/funcTest/groovy/me/champeau/jmh/AbstractFuncSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ abstract class AbstractFuncSpec extends Specification {
GradleVersion.current()
]

protected static final List<String> TESTED_SHADOW_PLUGINS = [
'com.github.johnrengelman.shadow',
'io.github.goooler.shadow'
/** Plugin + min Gradle version the plugin supports. */
protected static final Map<String, GradleVersion> TESTED_SHADOW_PLUGINS = [
'com.gradleup.shadow': GradleVersion.version('8.3'),
'com.github.johnrengelman.shadow': GradleVersion.version('7.0')
]

protected static final Map<String, String> 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<Tuple2<String, GradleVersion>> 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
Expand All @@ -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
}
Expand All @@ -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) {
Expand Down
16 changes: 11 additions & 5 deletions src/funcTest/groovy/me/champeau/jmh/JmhWithShadowPluginSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ProjectWithDuplicateClassesSpec extends AbstractFuncSpec {

given:
usingGradleVersion(gradleVersion)
withoutConfigurationCache('shadow plugin unsupported')
disableConfigCacheForShadow(shadowPlugin)

and:
buildFile << """
Expand All @@ -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)"() {
Expand Down Expand Up @@ -131,7 +128,7 @@ class ProjectWithDuplicateClassesSpec extends AbstractFuncSpec {

given:
usingGradleVersion(gradleVersion)
withoutConfigurationCache('shadow plugin unsupported')
disableConfigCacheForShadow(shadowPlugin)

and:
buildFile << """
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ProjectWithDuplicateDependenciesSpec extends AbstractFuncSpec {

given:
usingGradleVersion(gradleVersion)
withoutConfigurationCache('shadow plugin unsupported')
disableConfigCacheForShadow(shadowPlugin)

and:
createBuildFile("""
Expand All @@ -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) {
Expand Down
29 changes: 0 additions & 29 deletions src/funcTest/resources/java-forked-shadow-project/build.gradle

This file was deleted.

16 changes: 0 additions & 16 deletions src/funcTest/resources/java-forked-shadow-project/settings.gradle

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Goooler marked this conversation as resolved.
Show resolved Hide resolved
Goooler marked this conversation as resolved.
Show resolved Hide resolved
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))
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/funcTest/resources/java-shadow-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
plugins {
id 'java'
id 'com.github.johnrengelman.shadow'
id 'shadowPlugin'
id 'me.champeau.jmh'
}

Expand All @@ -26,4 +26,4 @@ repositories {
jmh {
resultFormat = 'csv'
resultsFile = file('build/reports/benchmarks.csv')
}
}
33 changes: 0 additions & 33 deletions src/funcTest/resources/scala-forked-shadow-project/build.gradle

This file was deleted.

16 changes: 0 additions & 16 deletions src/funcTest/resources/scala-forked-shadow-project/settings.gradle

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/funcTest/resources/scala-shadow-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
plugins {
id 'scala'
id 'com.github.johnrengelman.shadow'
id 'shadowPlugin'
id 'me.champeau.jmh'
}

Expand Down
Loading