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 6 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
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
java-version: |
22
Goooler marked this conversation as resolved.
Show resolved Hide resolved
21
- uses: gradle/actions/setup-gradle@v4
- name: Execute Gradle build
run: ./gradlew build
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ dependencies {
testImplementation("org.spockframework:spock-core:2.3-groovy-3.0") {
exclude(mapOf("group" to "org.codehaus.groovy"))
}
pluginsUnderTest("com.gradleup.shadow:shadow-gradle-plugin:8.3.0")
pluginsUnderTest("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
pluginsUnderTest("io.github.goooler.shadow:shadow-gradle-plugin:8.1.8")

testImplementation("org.openjdk.jmh:jmh-core:$jmhVersion")
testImplementation("org.openjdk.jmh:jmh-generator-bytecode:$jmhVersion")
Expand Down
18 changes: 13 additions & 5 deletions src/funcTest/groovy/me/champeau/jmh/AbstractFuncSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@ 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('8.3')
Goooler marked this conversation as resolved.
Show resolved Hide resolved
]

protected static final Map<String, String> TESTED_SHADOW_PLUGIN_FOLDERS = [
'com.github.johnrengelman.shadow': 'shadow',
'io.github.goooler.shadow': 'forked-shadow'
'com.gradleup.shadow': 'shadow',
'com.github.johnrengelman.shadow': 'shadow-old'
]

/** List of plugin + Gradle version combinations. */
protected static final List<Tuple2<String, GradleVersion>> TESTED_SHADOW_GRADLE_COMBINATIONS =
TESTED_SHADOW_PLUGINS.collect { shadowGradle ->
TESTED_GRADLE_VERSIONS.findAll { gradle -> gradle >= shadowGradle.value }
.collect { gradle -> new Tuple(shadowGradle.key, gradle) }
}.inject([]) { a, b -> a.addAll(b); a }

@TempDir
File temporaryFolder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class JmhWithShadowPluginSpec extends AbstractFuncSpec {
def "Run #language benchmarks that are packaged with Shadow plugin (#gradleVersion #language #shadowPlugin)"() {

given:
System.err.println("LANG: $language")
System.err.println("G: $gradleVersion")
System.err.println("P: $shadowPlugin")
Goooler marked this conversation as resolved.
Show resolved Hide resolved
Goooler marked this conversation as resolved.
Show resolved Hide resolved
usingSample("${language.toLowerCase()}-${TESTED_SHADOW_PLUGIN_FOLDERS[shadowPlugin]}-project")
usingGradleVersion(gradleVersion)
withoutConfigurationCache('shadow plugin unsupported')
Expand All @@ -37,10 +40,9 @@ class JmhWithShadowPluginSpec extends AbstractFuncSpec {
benchmarksCsv.text.contains(language + 'Benchmark.sqrtBenchmark')

where:
[language, gradleVersion, shadowPlugin] << [
['Java', 'Scala'],
TESTED_GRADLE_VERSIONS,
TESTED_SHADOW_PLUGINS
].combinations()
[language, gradleVersion, shadowPlugin] <<
TESTED_SHADOW_GRADLE_COMBINATIONS.collect { plugin, gradle ->
['Java', 'Scala'].collect { lang -> [lang, gradle, plugin ] }
}.inject([]) { a, b -> a.addAll(b); a }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ 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))
languageVersion.set(JavaLanguageVersion.of(22))
})
}

// Then configure the JMH Tasks to build with Java 15
snazy marked this conversation as resolved.
Show resolved Hide resolved
tasks.withType(me.champeau.jmh.WithJavaToolchain).configureEach {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(15))
languageVersion.set(JavaLanguageVersion.of(22))
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
plugins {
id 'java'
id 'io.github.goooler.shadow'
id 'com.github.johnrengelman.shadow'
Goooler marked this conversation as resolved.
Show resolved Hide resolved
id 'me.champeau.jmh'
}

Expand All @@ -26,4 +26,4 @@ repositories {
jmh {
resultFormat = 'csv'
resultsFile = file('build/reports/benchmarks.csv')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
rootProject.name = "java-forked-shadow-project"
rootProject.name = "java-shadow-old-project"
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 'com.gradleup.shadow'
id 'me.champeau.jmh'
}

Expand All @@ -26,4 +26,4 @@ repositories {
jmh {
resultFormat = 'csv'
resultsFile = file('build/reports/benchmarks.csv')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
plugins {
id 'scala'
id 'io.github.goooler.shadow'
id 'com.gradleup.shadow'
id 'me.champeau.jmh'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
rootProject.name = "scala-forked-shadow-project"
rootProject.name = "scala-shadow-project"
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 'com.gradleup.shadow'
id 'me.champeau.jmh'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
rootProject.name = "scala-shadow-project"
rootProject.name = "scala-forked-shadow-project"
2 changes: 1 addition & 1 deletion src/main/groovy/me/champeau/jmh/JMHPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class JMHPlugin implements Plugin<Project> {
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)
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/me/champeau/jmh/JMHPluginTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}

Expand Down