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
3 changes: 1 addition & 2 deletions docs/configuration/merging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,14 @@ as expected because the `duplicatesStrategy` will exclude the duplicate service
Want [`ResourceTransformer`][ResourceTransformer]s and `duplicatesStrategy` to work together? There are several ways to
do it:

- Use [`eachFile`][Jar.eachFile] or [`filesMatching`][Jar.filesMatching] to override the strategy for specific files.
- Use [`filesMatching`][Jar.filesMatching] to override the strategy for specific files.
- Keep `duplicatesStrategy = INCLUDE` and write your own [`ResourceTransformer`][ResourceTransformer] to handle duplicates.

If you just want to keep the current behavior and preserve the first found resources, there is a simple built-in one
called [`PreserveFirstFoundResourceTransformer`][PreserveFirstFoundResourceTransformer].


[AbstractCopyTask]: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.AbstractCopyTask.html
[Jar.eachFile]: https://docs.gradle.org/current/dsl/org.gradle.jvm.tasks.Jar.html#org.gradle.jvm.tasks.Jar:eachFile(groovy.lang.Closure)
[Jar.filesMatching]: https://docs.gradle.org/current/dsl/org.gradle.jvm.tasks.Jar.html#org.gradle.jvm.tasks.Jar:filesMatching(java.lang.Iterable,%20org.gradle.api.Action)
[AppendingTransformer]: ../../api/shadow/com.github.jengelman.gradle.plugins.shadow.transformers/-appending-transformer/index.html
[DuplicatesStrategy]: https://docs.gradle.org/current/javadoc/org/gradle/api/file/DuplicatesStrategy.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,28 +225,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() {
}

@Test
fun strategyExcludeCanBeOverriddenByEachFile() {
writeDuplicatesStrategy(DuplicatesStrategy.EXCLUDE)
projectScriptPath.appendText(
"""
$shadowJar {
eachFile {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}
""".trimIndent(),
)

run(shadowJarTask)

assertThat(outputShadowJar).useAll {
getContent(ENTRY_SERVICES_SHADE).isEqualTo(CONTENT_ONE_TWO)
getContent(ENTRY_SERVICES_FOO).isEqualTo("one\ntwo")
}
}

@Test
fun strategyExcludeCanBeOverriddenByFileMatching() {
fun strategyExcludeCanBeOverriddenByFilesMatching() {
writeDuplicatesStrategy(DuplicatesStrategy.EXCLUDE)
projectScriptPath.appendText(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public abstract class ShadowJar : Jar() {
/**
* Returns the strategy to use when trying to copy more than one file to the same destination.
*
* This strategy can be overridden for individual files by using [eachFile] or [filesMatching].
* This strategy can be overridden for individual files by using [filesMatching].
*
* The default value is [INCLUDE]. Different strategies will lead to different results for
* `foo/bar` files in the JARs to be merged:
Expand All @@ -212,13 +212,12 @@ public abstract class ShadowJar : Jar() {
* [EXCLUDE], as the service files are excluded beforehand. Want [ResourceTransformer]s and the strategy to work
* together? There are several ways to do it:
*
* - Use [eachFile] or [filesMatching] to override the strategy for specific files.
* - Use [filesMatching] to override the strategy for specific files.
* - Keep `duplicatesStrategy = INCLUDE` and write your own [ResourceTransformer] to handle duplicates.
*
* If you just want to keep the current behavior and preserve the first found resources, there is a simple built-in one
* called [PreserveFirstFoundResourceTransformer].
*
* @see [eachFile]
* @see [filesMatching]
* @see [DuplicatesStrategy]
* @see [CopySpec.duplicatesStrategy]
Expand Down
Loading