Skip to content
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
42 changes: 42 additions & 0 deletions src/docs/publishing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,45 @@ 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 trimming
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 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.
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"
}
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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
Expand Down Expand Up @@ -62,6 +63,37 @@ 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"))
assertShadowVariantCommon(gmmAdapter.fromJson(repoPath("shadow/maven/1.0/maven-1.0.module")))
}

@Issue(
"https://github.com/GradleUp/shadow/issues/860",
"https://github.com/GradleUp/shadow/issues/945",
Expand Down
Loading