From e5c1e7fd35619951e16bcdc3a99d288a96204cb9 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 27 Feb 2023 14:23:08 +0800 Subject: [PATCH 1/8] Enable CC for all plugin tests --- build.gradle | 15 +++++++++++- .../plugins/shadow/ApplicationSpec.groovy | 6 ++--- .../shadow/ConfigurationCacheSpec.groovy | 16 ++++++------- .../plugins/shadow/ShadowPluginSpec.groovy | 24 +++++++++---------- .../plugins/shadow/TransformerSpec.groovy | 2 +- .../shadow/util/PluginSpecification.groovy | 2 +- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index fa921375f..f5ec2c169 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ repositories { mavenCentral() } -test { +tasks.withType(Test).configureEach { useJUnitPlatform() if (System.env.CI == 'true') { @@ -39,6 +39,19 @@ test { } systemProperty 'java.io.tmpdir', buildDir.absolutePath + + // Required to test configuration cache in tests when using withDebug() + // https://github.com/gradle/gradle/issues/22765#issuecomment-1339427241 + jvmArgs( + "--add-opens", + "java.base/java.util=ALL-UNNAMED", + "--add-opens", + "java.base/java.util.concurrent.atomic=ALL-UNNAMED", + "--add-opens", + "java.base/java.lang.invoke=ALL-UNNAMED", + "--add-opens", + "java.base/java.net=ALL-UNNAMED", + ) } // jar { diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy index b972c2e28..26db3b541 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy @@ -43,7 +43,7 @@ class ApplicationSpec extends PluginSpecification { settingsFile << "rootProject.name = 'myapp'" when: - BuildResult result = run('runShadow', '--stacktrace') + BuildResult result = run('runShadow') then: 'tests that runShadow executed and exited' assert result.output.contains('TestApp: Hello World! (foo)') @@ -120,7 +120,7 @@ class ApplicationSpec extends PluginSpecification { """.stripIndent() when: - BuildResult result = run('runShadow', '--stacktrace') + BuildResult result = run('runShadow') then: 'tests that runShadow executed and exited' assert result.output.contains('Running application with JDK 17') @@ -183,7 +183,7 @@ class ApplicationSpec extends PluginSpecification { settingsFile << "rootProject.name = 'myapp'" when: - run('shadowDistZip', '--stacktrace') + run('shadowDistZip') then: 'Check that the distribution zip was created' File zip = getFile('build/distributions/myapp-shadow-1.0.zip') diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.groovy index 0dfe14e38..b2476e59b 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.groovy @@ -49,8 +49,8 @@ class ConfigurationCacheSpec extends PluginSpecification { settingsFile << "rootProject.name = 'myapp'" when: - run('--configuration-cache', 'shadowJar') - def result = run('--configuration-cache', 'shadowJar') + run('shadowJar') + def result = run('shadowJar') then: result.output.contains("Reusing configuration cache.") @@ -65,9 +65,9 @@ class ConfigurationCacheSpec extends PluginSpecification { """.stripIndent() when: - run('--configuration-cache', 'shadowJar') + run('shadowJar') output.delete() - def result = run('--configuration-cache', 'shadowJar') + def result = run('shadowJar') then: contains(output, ['a.properties', 'b.properties']) @@ -117,9 +117,9 @@ class ConfigurationCacheSpec extends PluginSpecification { def output = getFile('server/build/libs/server-all.jar') when: - run('--configuration-cache', 'shadowJar', '-s') + run('shadowJar', '-s') output.delete() - def result = run('--configuration-cache', 'shadowJar', '-s') + def result = run('shadowJar', '-s') then: output.exists() @@ -160,8 +160,8 @@ class ConfigurationCacheSpec extends PluginSpecification { """.stripIndent() when: - run('--configuration-cache', 'shadowJar', '-s') - def result = run('--configuration-cache', 'shadowJar', '-s') + run('shadowJar', '-s') + def result = run('shadowJar', '-s') then: result.output.contains(":lib:shadowJar UP-TO-DATE") diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy index ab9ab0c7b..c268ffd9a 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy @@ -256,7 +256,7 @@ class ShadowPluginSpec extends PluginSpecification { File serverOutput = getFile('server/build/libs/server-all.jar') when: - runWithDebug(':server:shadowJar', '--stacktrace') + runWithDebug(':server:shadowJar') then: serverOutput.exists() @@ -311,7 +311,7 @@ class ShadowPluginSpec extends PluginSpecification { File serverOutput = getFile('server/build/libs/server-all.jar') when: - runWithDebug(':server:shadowJar', '--stacktrace') + runWithDebug(':server:shadowJar') then: serverOutput.exists() @@ -364,7 +364,7 @@ class ShadowPluginSpec extends PluginSpecification { File serverOutput = file('server/build/libs/server-all.jar') when: - runWithDebug(':server:shadowJar', '--stacktrace') + runWithDebug(':server:shadowJar') then: contains(serverOutput, [ @@ -419,7 +419,7 @@ class ShadowPluginSpec extends PluginSpecification { File serverOutput = file('server/build/libs/server-all.jar') when: - runWithDebug(':server:shadowJar', '--stacktrace') + runWithDebug(':server:shadowJar') then: contains(serverOutput, [ @@ -472,7 +472,7 @@ class ShadowPluginSpec extends PluginSpecification { File serverOutput = file('server/build/libs/server-all.jar') when: - runWithDebug(':server:shadowJar', '--stacktrace') + runWithDebug(':server:shadowJar') then: contains(serverOutput, [ @@ -550,7 +550,7 @@ class ShadowPluginSpec extends PluginSpecification { File serverOutput = getFile('impl/build/libs/impl-all.jar') when: - runWithDebug(':impl:shadowJar', '--stacktrace') + runWithDebug(':impl:shadowJar') then: serverOutput.exists() @@ -626,7 +626,7 @@ class ShadowPluginSpec extends PluginSpecification { File serverOutput = getFile('impl/build/libs/impl-all.jar') when: - runWithDebug(':impl:shadowJar', '--stacktrace') + runWithDebug(':impl:shadowJar') then: serverOutput.exists() @@ -992,7 +992,7 @@ class ShadowPluginSpec extends PluginSpecification { """.stripIndent() when: - run('shadowJar', '--stacktrace') + run('shadowJar') then: assert output.exists() @@ -1040,7 +1040,7 @@ class ShadowPluginSpec extends PluginSpecification { File serverOutput = getFile('impl/build/libs/impl-1.0-all.jar') when: - runWithDebug(':impl:shadowJar', '--stacktrace') + runWithDebug(':impl:shadowJar') then: serverOutput.exists() @@ -1112,7 +1112,7 @@ class ShadowPluginSpec extends PluginSpecification { settingsFile << "rootProject.name = 'myapp'" when: - BuildResult result = run('runShadow', '--stacktrace') + BuildResult result = run('runShadow') then: 'tests that runShadow executed and exited' assert result.output.contains('TestApp: Hello World! (foo)') @@ -1170,7 +1170,7 @@ class ShadowPluginSpec extends PluginSpecification { """.stripIndent() when: - BuildResult result = run('runShadow', '--stacktrace') + BuildResult result = run('runShadow') then: 'tests that runShadow executed and exited' assert result.output.contains('TestApp: Hello World! (foo)') @@ -1212,7 +1212,7 @@ class ShadowPluginSpec extends PluginSpecification { """.stripIndent() when: - BuildResult result = run('runShadow', '--stacktrace') + BuildResult result = run('runShadow') then: 'tests that runShadow executed and exited' assert result.output.contains('TestApp: Hello World! (foo)') diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy index 77dcc5a01..996d03458 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy @@ -745,7 +745,7 @@ staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write( """.stripIndent() when: - run('shadowJar', '--warning-mode=all', '--stacktrace') + run('shadowJar', '--warning-mode=all') then: assert output.exists() diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 102a1d200..afaa504db 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -82,7 +82,7 @@ class PluginSpecification extends Specification { } GradleRunner runner(Collection tasks) { - runner.withArguments(["-Dorg.gradle.warning.mode=all"] + tasks.toList()) + runner.withArguments(["-Dorg.gradle.warning.mode=all", "--configuration-cache", "--stacktrace"] + tasks.toList()) } void assertNoDeprecationWarnings(BuildResult result) { From ed4ab3568616cb91416bb9ade12ac3575a5628e9 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 27 Feb 2023 16:21:20 +0800 Subject: [PATCH 2/8] Mark installShadowDist is not compatible with CC --- .../gradle/plugins/shadow/ShadowApplicationPlugin.groovy | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy index cc60e8649..95d3bc43f 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy @@ -93,8 +93,9 @@ class ShadowApplicationPlugin implements Plugin { } protected void configureInstallTask(Project project) { - project.tasks.named(SHADOW_INSTALL_TASK_NAME).configure { installTask -> - installTask.doFirst { Sync task -> + project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync).configure { task -> + notCompatibleWithConfigurationCache('https://github.com/johnrengelman/shadow/issues/775') + task.doFirst { if (task.destinationDir.directory) { if (task.destinationDir.listFiles().size() != 0 && (!new File(task.destinationDir, 'lib').directory || !new File(task.destinationDir, 'bin').directory)) { throw new GradleException("The specified installation directory '${task.destinationDir}' is neither empty nor does it contain an installation for '${javaApplication.applicationName}'.\n" + @@ -104,7 +105,7 @@ class ShadowApplicationPlugin implements Plugin { } } } - installTask.doLast { Sync task -> + task.doLast { project.ant.chmod(file: "${task.destinationDir.absolutePath}/bin/${javaApplication.applicationName}", perm: 'ugo+x') } } From 04180079a72df3c92ea45aa432726585a51f12a3 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 28 Feb 2023 14:03:50 +0800 Subject: [PATCH 3/8] Defer AppendingTransformer.data initialization --- .../transformers/AppendingTransformer.groovy | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformer.groovy index ca56e7f18..c965947b1 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformer.groovy @@ -41,7 +41,10 @@ class AppendingTransformer implements Transformer { @Input String resource - private ByteArrayOutputStream data = new ByteArrayOutputStream() + /** + * Defer initialization, see https://github.com/johnrengelman/shadow/issues/763 + */ + private ByteArrayOutputStream data boolean canTransformResource(FileTreeElement element) { def path = element.relativePath.pathString @@ -53,6 +56,10 @@ class AppendingTransformer implements Transformer { } void transform(TransformerContext context) { + if (data == null) { + data = new ByteArrayOutputStream() + } + IOUtil.copy(context.is, data) data.write('\n'.bytes) @@ -60,10 +67,14 @@ class AppendingTransformer implements Transformer { } boolean hasTransformedResource() { - return data.size() > 0 + return data?.size() > 0 } void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) { + if (data == null) { + data = new ByteArrayOutputStream() + } + ZipEntry entry = new ZipEntry(resource) entry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, entry.time) os.putNextEntry(entry) From 85b9e06c8c2d1e239748bcd8dad9922b5a21f79c Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 28 Feb 2023 12:56:23 +0800 Subject: [PATCH 4/8] Fix CC issues in tests --- .../gradle/plugins/shadow/ApplicationSpec.groovy | 2 +- .../jengelman/gradle/plugins/shadow/PublishingSpec.groovy | 8 ++++++++ .../plugins/shadow/caching/TransformCachingSpec.groovy | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy index 26db3b541..04e4b78c8 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy @@ -105,7 +105,7 @@ class ApplicationSpec extends PluginSpecification { runShadow { args 'foo' doFirst { - project.logger.lifecycle("Running application with JDK \${it.javaLauncher.get().metadata.languageVersion.asInt()}") + logger.lifecycle("Running application with JDK \${it.javaLauncher.get().metadata.languageVersion.asInt()}") } } """.stripIndent() diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index 7ea155900..856a0db23 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -52,6 +52,10 @@ class PublishingSpec extends PluginSpecification { } } } + + tasks.withType(org.gradle.api.publish.maven.tasks.GenerateMavenPom).configureEach { + notCompatibleWithConfigurationCache('https://github.com/gradle/gradle/issues/21926') + } """.stripIndent() when: @@ -149,6 +153,10 @@ class PublishingSpec extends PluginSpecification { } } } + + tasks.withType(org.gradle.api.publish.maven.tasks.GenerateMavenPom).configureEach { + notCompatibleWithConfigurationCache('https://github.com/gradle/gradle/issues/21926') + } """.stripMargin() when: diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/TransformCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/TransformCachingSpec.groovy index 30ad22213..e6ed6c1ee 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/TransformCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/TransformCachingSpec.groovy @@ -47,6 +47,7 @@ class TransformCachingSpec extends AbstractCachingSpec { } shadowJar { + notCompatibleWithConfigurationCache('CustomTransformer is not cacheable') transform(CustomTransformer) } """.stripIndent() From 6bbc4010a0cd6e50a50a40f1c819fa6f3e8735d3 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 3 Mar 2023 01:40:58 +0800 Subject: [PATCH 5/8] Support CC in ShadowExtension.component --- src/docs/publishing/README.md | 2 +- .../plugins/shadow/ShadowBasePlugin.groovy | 2 +- .../plugins/shadow/ShadowExtension.groovy | 44 +++++++++++-------- .../plugins/shadow/PublishingSpec.groovy | 12 +---- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md index e2aadc75d..9b8068307 100644 --- a/src/docs/publishing/README.md +++ b/src/docs/publishing/README.md @@ -16,7 +16,7 @@ apply plugin: 'com.github.johnrengelman.shadow' publishing { publications { shadow(MavenPublication) { publication -> - project.shadow.component(publication) + project.shadow.component(project, publication) } } repositories { diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy index 1f7a3a7d4..c8e3ea1d7 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy @@ -16,7 +16,7 @@ class ShadowBasePlugin implements Plugin { if (GradleVersion.current() < GradleVersion.version("8.0")) { throw new GradleException("This version of Shadow supports Gradle 8.0+ only. Please upgrade.") } - project.extensions.create(EXTENSION_NAME, ShadowExtension, project) + project.extensions.create(EXTENSION_NAME, ShadowExtension) createShadowConfiguration(project) project.tasks.register(KnowsTask.NAME, KnowsTask) { knows -> diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy index 743e566a8..9aa65c3f5 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy @@ -3,22 +3,13 @@ package com.github.jengelman.gradle.plugins.shadow import org.gradle.api.Project import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.SelfResolvingDependency -import org.gradle.api.file.CopySpec import org.gradle.api.publish.maven.MavenPom import org.gradle.api.publish.maven.MavenPublication import org.gradle.util.GradleVersion class ShadowExtension { - CopySpec applicationDistribution - Project project - - ShadowExtension(Project project) { - this.project = project - applicationDistribution = project.copySpec {} - } - - void component(MavenPublication publication) { + void component(Project project, MavenPublication publication) { if (GradleVersion.current() >= GradleVersion.version("6.6")) { publication.artifact(project.tasks.named("shadowJar")) @@ -26,19 +17,36 @@ class ShadowExtension { publication.artifact(project.tasks.shadowJar) } + final def allDependencies = project.provider { + project.configurations.shadow.allDependencies.collect { + if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) { + new Dep(it.group, it.name, it.version) + } + } + } publication.pom { MavenPom pom -> pom.withXml { xml -> def dependenciesNode = xml.asNode().get('dependencies') ?: xml.asNode().appendNode('dependencies') - project.configurations.shadow.allDependencies.each { - if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) { - def dependencyNode = dependenciesNode.appendNode('dependency') - dependencyNode.appendNode('groupId', it.group) - dependencyNode.appendNode('artifactId', it.name) - dependencyNode.appendNode('version', it.version) - dependencyNode.appendNode('scope', 'runtime') - } + allDependencies.get().each { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) + dependencyNode.appendNode('scope', 'runtime') } } } } + + private class Dep { + String group + String name + String version + + Dep(String group, String name, String version) { + this.group = group + this.name = name + this.version = version + } + } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index 856a0db23..2f0a68153 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -42,7 +42,7 @@ class PublishingSpec extends PluginSpecification { publishing { publications { shadow(MavenPublication) { publication -> - project.shadow.component(publication) + project.shadow.component(project, publication) artifactId = 'maven-all' } } @@ -52,10 +52,6 @@ class PublishingSpec extends PluginSpecification { } } } - - tasks.withType(org.gradle.api.publish.maven.tasks.GenerateMavenPom).configureEach { - notCompatibleWithConfigurationCache('https://github.com/gradle/gradle/issues/21926') - } """.stripIndent() when: @@ -148,15 +144,11 @@ class PublishingSpec extends PluginSpecification { publishing { publications { shadow(MavenPublication) { publication -> - project.shadow.component(publication) + project.shadow.component(project, publication) artifactId = 'maven-all' } } } - - tasks.withType(org.gradle.api.publish.maven.tasks.GenerateMavenPom).configureEach { - notCompatibleWithConfigurationCache('https://github.com/gradle/gradle/issues/21926') - } """.stripMargin() when: From 3543ca6559aa81d33ed1f4d7338d150a2da3fd7c Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Mar 2023 20:45:50 +0800 Subject: [PATCH 6/8] Make installShadowDist compat CC --- .../gradle/plugins/shadow/ShadowApplicationPlugin.groovy | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy index 95d3bc43f..f7688c7f2 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy @@ -94,7 +94,6 @@ class ShadowApplicationPlugin implements Plugin { protected void configureInstallTask(Project project) { project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync).configure { task -> - notCompatibleWithConfigurationCache('https://github.com/johnrengelman/shadow/issues/775') task.doFirst { if (task.destinationDir.directory) { if (task.destinationDir.listFiles().size() != 0 && (!new File(task.destinationDir, 'lib').directory || !new File(task.destinationDir, 'bin').directory)) { @@ -106,7 +105,11 @@ class ShadowApplicationPlugin implements Plugin { } } task.doLast { - project.ant.chmod(file: "${task.destinationDir.absolutePath}/bin/${javaApplication.applicationName}", perm: 'ugo+x') + task.eachFile { + if (it.path == "bin/${javaApplication.applicationName}") { + it.mode = 0x755 + } + } } } } From 95d3da48a7f0dbdeff5b0da3501f4f24110ea800 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Mar 2023 23:16:25 +0800 Subject: [PATCH 7/8] Remove project in InheritManifest.inheritFrom Follow up b1d87c23302d62f61d8cf544b2a6a5ede227c6b1. --- src/docs/configuration/README.md | 2 +- .../gradle/plugins/shadow/ShadowJavaPlugin.groovy | 2 +- .../shadow/tasks/DefaultInheritManifest.groovy | 11 +++++++---- .../plugins/shadow/tasks/InheritManifest.groovy | 5 ++--- .../gradle/plugins/shadow/tasks/ShadowJar.java | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/docs/configuration/README.md b/src/docs/configuration/README.md index 483518d54..8aa752a82 100644 --- a/src/docs/configuration/README.md +++ b/src/docs/configuration/README.md @@ -97,7 +97,7 @@ task testJar(type: Jar) { shadowJar { manifest { - inheritFrom(project, project.tasks.testJar.manifest) + inheritFrom(project.tasks.testJar.manifest) } } ``` diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy index 3808cf75e..4c3f578be 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy @@ -68,7 +68,7 @@ class ShadowJavaPlugin implements Plugin { } } } - shadow.manifest.inheritFrom(project, project.tasks.jar.manifest) + shadow.manifest.inheritFrom(project.tasks.jar.manifest) def libsProvider = project.provider { -> [project.tasks.jar.manifest.attributes.get('Class-Path')] } def files = project.objects.fileCollection().from { -> project.configurations.findByName(ShadowBasePlugin.CONFIGURATION_NAME) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy index 819fd6833..6fbcd7de1 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy @@ -14,21 +14,24 @@ class DefaultInheritManifest implements InheritManifest { private List inheritMergeSpecs = [] + private final transient Project project + private final FileResolver fileResolver private final Manifest internalManifest - DefaultInheritManifest(FileResolver fileResolver) { + DefaultInheritManifest(Project project, FileResolver fileResolver) { + this.project = project this.internalManifest = new DefaultManifest(fileResolver) this.fileResolver = fileResolver } - InheritManifest inheritFrom(Project project, Object... inheritPaths) { - inheritFrom(project, inheritPaths, null) + InheritManifest inheritFrom(Object... inheritPaths) { + inheritFrom(inheritPaths, null) return this } - InheritManifest inheritFrom(Project project, Object inheritPaths, Closure closure) { + InheritManifest inheritFrom(Object inheritPaths, Closure closure) { DefaultManifestMergeSpec mergeSpec = new DefaultManifestMergeSpec() mergeSpec.from(inheritPaths) inheritMergeSpecs.add(mergeSpec) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.groovy index 10be50626..1cfed3c4c 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/InheritManifest.groovy @@ -1,11 +1,10 @@ package com.github.jengelman.gradle.plugins.shadow.tasks -import org.gradle.api.Project import org.gradle.api.java.archives.Manifest interface InheritManifest extends Manifest { - InheritManifest inheritFrom(Project project, Object... inheritPaths) + InheritManifest inheritFrom(Object... inheritPaths) - InheritManifest inheritFrom(Project project, Object inheritPaths, Closure closure) + InheritManifest inheritFrom(inheritPaths, Closure closure) } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java index 9dc21742d..067294854 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java @@ -54,7 +54,7 @@ public ShadowJar() { setDuplicatesStrategy(DuplicatesStrategy.INCLUDE); //shadow filters out files later. This was the default behavior in Gradle < 6.x dependencyFilter = new DefaultDependencyFilter(getProject()); dependencyFilterForMinimize = new MinimizeDependencyFilter(getProject()); - setManifest(new DefaultInheritManifest(getServices().get(FileResolver.class))); + setManifest(new DefaultInheritManifest(getProject(), getServices().get(FileResolver.class))); transformers = new ArrayList<>(); relocators = new ArrayList<>(); configurations = new ArrayList<>(); From a86645c0dcb82fcd4663c313ed5345481478a85b Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 9 Mar 2023 10:09:21 +0800 Subject: [PATCH 8/8] Init fields in ShadowExtension's constructor Follow up 6bbc4010a0cd6e50a50a40f1c819fa6f3e8735d3. --- src/docs/publishing/README.md | 2 +- .../plugins/shadow/ShadowBasePlugin.groovy | 2 +- .../plugins/shadow/ShadowExtension.groovy | 31 +++++++++++-------- .../plugins/shadow/PublishingSpec.groovy | 4 +-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md index 9b8068307..e2aadc75d 100644 --- a/src/docs/publishing/README.md +++ b/src/docs/publishing/README.md @@ -16,7 +16,7 @@ apply plugin: 'com.github.johnrengelman.shadow' publishing { publications { shadow(MavenPublication) { publication -> - project.shadow.component(project, publication) + project.shadow.component(publication) } } repositories { diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy index c8e3ea1d7..1f7a3a7d4 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy @@ -16,7 +16,7 @@ class ShadowBasePlugin implements Plugin { if (GradleVersion.current() < GradleVersion.version("8.0")) { throw new GradleException("This version of Shadow supports Gradle 8.0+ only. Please upgrade.") } - project.extensions.create(EXTENSION_NAME, ShadowExtension) + project.extensions.create(EXTENSION_NAME, ShadowExtension, project) createShadowConfiguration(project) project.tasks.register(KnowsTask.NAME, KnowsTask) { knows -> diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy index 9aa65c3f5..865b3a3e1 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowExtension.groovy @@ -1,33 +1,38 @@ package com.github.jengelman.gradle.plugins.shadow +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.api.Project import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.SelfResolvingDependency +import org.gradle.api.file.RegularFile +import org.gradle.api.provider.Provider import org.gradle.api.publish.maven.MavenPom import org.gradle.api.publish.maven.MavenPublication -import org.gradle.util.GradleVersion class ShadowExtension { + private final Provider> archiveFile + private final Provider> allDependencies - void component(Project project, MavenPublication publication) { - - if (GradleVersion.current() >= GradleVersion.version("6.6")) { - publication.artifact(project.tasks.named("shadowJar")) - } else { - publication.artifact(project.tasks.shadowJar) - } - - final def allDependencies = project.provider { - project.configurations.shadow.allDependencies.collect { - if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) { + ShadowExtension(Project project) { + archiveFile = project.provider { project.tasks.withType(ShadowJar).getByName("shadowJar").archiveFile } + allDependencies = project.provider { + project.configurations.getByName("shadow").allDependencies.collect { + if ((it instanceof ProjectDependency) || !(it instanceof SelfResolvingDependency)) { new Dep(it.group, it.name, it.version) } } } + } + + void component(MavenPublication publication) { + publication.artifact(archiveFile.get()) + + // Don't inline this variable, it seems Groovy closure capturing is confused by the field instead of a local variable. + final def allDeps = allDependencies publication.pom { MavenPom pom -> pom.withXml { xml -> def dependenciesNode = xml.asNode().get('dependencies') ?: xml.asNode().appendNode('dependencies') - allDependencies.get().each { + allDeps.get().each { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index 2f0a68153..7ea155900 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -42,7 +42,7 @@ class PublishingSpec extends PluginSpecification { publishing { publications { shadow(MavenPublication) { publication -> - project.shadow.component(project, publication) + project.shadow.component(publication) artifactId = 'maven-all' } } @@ -144,7 +144,7 @@ class PublishingSpec extends PluginSpecification { publishing { publications { shadow(MavenPublication) { publication -> - project.shadow.component(project, publication) + project.shadow.component(publication) artifactId = 'maven-all' } }