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
1 change: 1 addition & 0 deletions api/shadow.api
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public final class com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin$C
public abstract interface class com/github/jengelman/gradle/plugins/shadow/ShadowExtension {
public abstract fun getAddShadowVariantIntoJavaComponent ()Lorg/gradle/api/provider/Property;
public abstract fun getAddTargetJvmVersionAttribute ()Lorg/gradle/api/provider/Property;
public abstract fun getBundlingAttribute ()Lorg/gradle/api/provider/Property;
}

public abstract class com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin : org/gradle/api/Plugin {
Expand Down
8 changes: 8 additions & 0 deletions docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
- Support relocating Kotlin module files. ([#1539](https://github.com/GradleUp/shadow/pull/1539))
The current implementation relocates all properties in `KotlinModuleMetadata` but `KmModule.optionalAnnotationClasses`
due to very limited usage of it. See more discussion [here](https://github.com/GradleUp/shadow/pull/1539#discussion_r2344237151).
- Allow overriding `BUNDLING_ATTRIBUTE` in GMM. ([#1773](https://github.com/GradleUp/shadow/pull/1773))
The `org.gradle.dependency.bundling` in shadowed JAR's Gradle Module Metadata is set to `shadowed` by default.
You can override it for now by:
```kotlin
shadow {
bundlingAttribute = Bundling.EMBEDDED
}
```

### Changed

Expand Down
22 changes: 22 additions & 0 deletions docs/publishing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,28 @@ you can disable this by setting the `addTargetJvmVersionAttribute` property in t
}
```

The BUNDLING attribute (`org.gradle.dependency.bundling`) of the shadowed variant is set to `shadowed` by default,
it is useful for consumers to distinguish between normal and shadowed dependencies. You can override this attribute by
setting the `bundlingAttribute` property in the `shadow` extension:

=== "Kotlin"

```kotlin
shadow {
// Per description of the attribute, you should set it to either `Bundling.SHADOWED` or `Bundling.EMBEDDED`.
bundlingAttribute = Bundling.EMBEDDED
}
```

=== "Groovy"

```groovy
shadow {
// Per description of the attribute, you should set it to either `Bundling.SHADOWED` or `Bundling.EMBEDDED`.
bundlingAttribute = Bundling.EMBEDDED
}
```

## Shadow Configuration and Publishing

The Shadow plugin provides a custom configuration (`configurations.shadow`) to specify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,33 @@ class PublishingTest : BasePluginTest() {
)
}

@Test
fun overrideBundlingAttrInGradleMetadata() {
projectScript.appendText(
publishConfiguration(
projectBlock = """
shadow {
bundlingAttribute = Bundling.EMBEDDED
}
""".trimIndent(),
shadowBlock = """
archiveClassifier = ''
archiveBaseName = 'maven-all'
""".trimIndent(),
),
)

publish()

assertShadowVariantCommon(
gmm = gmmAdapter.fromJson(repoPath("my/maven-all/1.0/maven-all-1.0.module")),
variantAttrs = commonVariantAttrs + arrayOf(
Bundling.BUNDLING_ATTRIBUTE.name to Bundling.EMBEDDED,
Usage.USAGE_ATTRIBUTE.name to Usage.JAVA_RUNTIME,
),
)
}

@Test
fun publishShadowJarInsteadOfJar() {
projectScript.appendText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.attributes.Bundling
import org.gradle.api.component.SoftwareComponentContainer
import org.gradle.api.distribution.DistributionContainer
import org.gradle.api.plugins.ExtensionContainer
Expand All @@ -22,6 +23,7 @@ public abstract class ShadowBasePlugin : Plugin<Project> {
with(extensions.create(EXTENSION_NAME, ShadowExtension::class.java)) {
addShadowVariantIntoJavaComponent.convention(true)
addTargetJvmVersionAttribute.convention(true)
bundlingAttribute.convention(Bundling.SHADOWED)
}
@Suppress("EagerGradleConfiguration") // this should be created eagerly.
configurations.create(CONFIGURATION_NAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.jengelman.gradle.plugins.shadow

import org.gradle.api.attributes.Bundling
import org.gradle.api.attributes.java.TargetJvmVersion
import org.gradle.api.provider.Property

Expand All @@ -19,4 +20,13 @@ public interface ShadowExtension {
* Defaults to `true`.
*/
public val addTargetJvmVersionAttribute: Property<Boolean>

/**
* The [Bundling] attribute to use for the Gradle Module Metadata.
*
* Per description of the attribute, you should set it to either [Bundling.SHADOWED] or [Bundling.EMBEDDED].
*
* Defaults to [Bundling.SHADOWED].
*/
public val bundlingAttribute: Property<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public abstract class ShadowJavaPlugin @Inject constructor(
LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
objects.named(LibraryElements::class.java, LibraryElements.JAR),
)
attrs.attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling::class.java, Bundling.SHADOWED))
attrs.attributeProvider(
Bundling.BUNDLING_ATTRIBUTE,
shadow.bundlingAttribute.map { attr -> objects.named(Bundling::class.java, attr) },
)
}
it.outgoing.artifact(tasks.shadowJar)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.shad
import org.gradle.api.Named
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.attributes.Bundling
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.plugins.ApplicationPlugin
import org.gradle.api.plugins.JavaPlugin
Expand Down Expand Up @@ -59,6 +60,7 @@ class ShadowPropertiesTest {
with(extensions.getByType(ShadowExtension::class.java)) {
assertThat(addShadowVariantIntoJavaComponent.get()).isTrue()
assertThat(addTargetJvmVersionAttribute.get()).isTrue()
assertThat(bundlingAttribute.get()).isEqualTo(Bundling.SHADOWED)
}
}

Expand Down