From ca4ab15a127ea56fd20a9f9ee0f602db73bb48b0 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 12 Jan 2025 19:30:01 +0800 Subject: [PATCH 1/7] Add publishShadowJarInsteadOfJarWithMavenPublishPlugin --- .../gradle/plugins/shadow/PublishingTest.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt index 167ba3626..4c4dcfe5f 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt @@ -9,6 +9,7 @@ import com.github.jengelman.gradle.plugins.shadow.util.Issue import com.github.jengelman.gradle.plugins.shadow.util.JarPath import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries +import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory @@ -58,6 +59,36 @@ class PublishingTest : BasePluginTest() { assertPomCommon(repoPath("shadow/maven-all/1.0/maven-all-1.0.pom")) } + @Test + fun publishShadowJarInsteadOfJarWithMavenPublishPlugin() { + projectScriptPath.appendText( + publishConfiguration( + shadowBlock = """ + archiveClassifier = '' + """.trimIndent(), + publicationsBlock = """ + shadow(MavenPublication) { + from components.shadow + } + """.trimIndent(), + ), + ) + + publish() + + assertThat(repoJarPath("shadow/maven/1.0/maven-1.0.jar")).useAll { + containsEntries( + "a.properties", + "a2.properties", + ) + doesNotContainEntries( + "b.properties", + ) + getMainAttr("Class-Path").isEqualTo("b-1.0.jar") + } + assertPomCommon(repoPath("shadow/maven/1.0/maven-1.0.pom")) + } + @Issue( "https://github.com/GradleUp/shadow/issues/860", "https://github.com/GradleUp/shadow/issues/945", From f2b9a3443d6c4634c54c70cbde48b7dec331b120 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 12 Jan 2025 19:41:46 +0800 Subject: [PATCH 2/7] Add an example in src/docs/publishing/README.md --- src/docs/publishing/README.md | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md index d87ccf8fc..5e55fda02 100644 --- a/src/docs/publishing/README.md +++ b/src/docs/publishing/README.md @@ -44,3 +44,44 @@ configuration of the POM file. This automatic configuration occurs _only_ when using the above methods for configuring publishing. If this behavior is not desirable, then publishing **must** be manually configured. + +# Publish the Shadowed JAR instead of the Original JAR + +You may want to publish the shadowed JAR instead of the original JAR. This can be done by trim +the `archiveClassifier` of the shadowed JAR like the following: + +```groovy +apply plugin: 'java' +apply plugin: 'maven-publish' +apply plugin: 'com.gradleup.shadow' + +group = 'shadow' +version = '1.0' + +dependencies { + // This will be bundled in the shadowed JAR. + implementation 'some:a:1.0' + // This will be excluded from the shadowed JAR but declared as a runtime dependency in `META-INF/MANIFEST.MF` + // file's `Class-Path` entry, and also in the POM file. + shadow 'some:b:1.0' + // This will be excluded from the shadowed JAR and not declared in the POM or `META-INF/MANIFEST.MF`. + compileOnly 'some:c:1.0' +} + +tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + archiveClassifier = '' +} + +publishing { + publications { + shadow(MavenPublication) { + from components.shadow + } + } + repositories { + maven { + url = "https://repo.myorg.com" + } + } +} +``` From 6c3c2b22d9d97e975dd7840852b3423aca4d4d3f Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Sun, 12 Jan 2025 20:16:48 +0800 Subject: [PATCH 3/7] Update src/docs/publishing/README.md --- src/docs/publishing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md index 5e55fda02..d38bc12bd 100644 --- a/src/docs/publishing/README.md +++ b/src/docs/publishing/README.md @@ -47,7 +47,7 @@ be manually configured. # Publish the Shadowed JAR instead of the Original JAR -You may want to publish the shadowed JAR instead of the original JAR. This can be done by trim +You may want to publish the shadowed JAR instead of the original JAR. This can be done by trimming the `archiveClassifier` of the shadowed JAR like the following: ```groovy From 1bf869009799797b669c5af17a747941aaab938f Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Sun, 12 Jan 2025 20:54:19 +0800 Subject: [PATCH 4/7] Update src/docs/publishing/README.md --- src/docs/publishing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md index d38bc12bd..6eafee228 100644 --- a/src/docs/publishing/README.md +++ b/src/docs/publishing/README.md @@ -59,7 +59,7 @@ group = 'shadow' version = '1.0' dependencies { - // This will be bundled in the shadowed JAR. + // This will be bundled in the shadowed JAR and not declared in the POM. implementation 'some:a:1.0' // This will be excluded from the shadowed JAR but declared as a runtime dependency in `META-INF/MANIFEST.MF` // file's `Class-Path` entry, and also in the POM file. From b6dc58d73d20782ad82ac132d6f7b29db065ddff Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 14 Jan 2025 10:55:38 +0800 Subject: [PATCH 5/7] Check shadowRuntimeElements --- .../com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt index 8c48deed4..18cd42fe6 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt @@ -91,6 +91,7 @@ class PublishingTest : BasePluginTest() { getMainAttr("Class-Path").isEqualTo("b-1.0.jar") } assertPomCommon(repoPath("shadow/maven/1.0/maven-1.0.pom")) + assertShadowVariantCommon(gmmAdapter.fromJson(repoPath("shadow/maven/1.0/maven-1.0.module"))) } @Issue( From 77ee7e2e1d02abc063ea356bc71a05eb8e45b8ee Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Tue, 14 Jan 2025 11:11:17 +0800 Subject: [PATCH 6/7] Update src/docs/publishing/README.md --- src/docs/publishing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md index 6eafee228..cd109793f 100644 --- a/src/docs/publishing/README.md +++ b/src/docs/publishing/README.md @@ -45,6 +45,7 @@ This automatic configuration occurs _only_ when using the above methods for configuring publishing. If this behavior is not desirable, then publishing **must** be manually configured. + # Publish the Shadowed JAR instead of the Original JAR You may want to publish the shadowed JAR instead of the original JAR. This can be done by trimming From 9a5c09bf58b771c00ee5c66f1c7ee36ae53ca93f Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Tue, 14 Jan 2025 11:35:38 +0800 Subject: [PATCH 7/7] Update src/docs/publishing/README.md --- src/docs/publishing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/publishing/README.md b/src/docs/publishing/README.md index cd109793f..e912b5137 100644 --- a/src/docs/publishing/README.md +++ b/src/docs/publishing/README.md @@ -46,7 +46,7 @@ configuring publishing. If this behavior is not desirable, then publishing **mus be manually configured. -# Publish the Shadowed JAR instead of the Original JAR +## Publish the Shadowed JAR instead of the Original JAR You may want to publish the shadowed JAR instead of the original JAR. This can be done by trimming the `archiveClassifier` of the shadowed JAR like the following: