You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document more about eachFile, filesMatching, and filesNotMatching (#1682)
* Mention `eachFile` and `filesNotMatching`
* New steps
* Use `ParameterizedTest` for `strategyCanBeOverriddenByEachFile`
* Cleanups
* Add more examples
* Merge duplicate steps
* Add the optional step at the last
Copy file name to clipboardExpand all lines: docs/configuration/merging/README.md
+106-7Lines changed: 106 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,20 +77,117 @@ Different strategies will lead to different results for `foo/bar` files in the J
77
77
```
78
78
79
79
The [`ResourceTransformer`][ResourceTransformer]s like [`ServiceFileTransformer`][ServiceFileTransformer] will not work
80
-
as expected as the duplicate resource files fed for them are excluded beforehand. However, this behavior might be what you expected for duplicate `foo/bar` files, preventing them from being included.
80
+
as expected as the duplicate resource files fed for them are excluded beforehand. However, this behavior might be what
81
+
you expected for duplicate `foo/bar` files, preventing them from being included.
81
82
82
-
Want [`ResourceTransformer`][ResourceTransformer]s and `duplicatesStrategy` to work together? There are several steps
83
-
to take:
83
+
Want [`ResourceTransformer`][ResourceTransformer]s and `duplicatesStrategy` to work together? There are several common
84
+
steps to take:
84
85
85
-
1. Set the strategy to `INCLUDE` or `WARN`.
86
+
1. Set the default strategy to `INCLUDE` or `WARN`.
86
87
2. Apply your [`ResourceTransformer`][ResourceTransformer]s.
87
88
3. Remove duplicate entries by
88
-
- overriding the default strategy for specific files using [`filesMatching`][Jar.filesMatching]
89
+
- overriding the default strategy for specific files to `EXCLUDE` or `FAIL` using
90
+
[`filesMatching`][Jar.filesMatching], [`filesNotMatching`][Jar.filesNotMatching], or [`eachFile`][Jar.eachFile] functions
89
91
- or applying [`PreserveFirstFoundResourceTransformer`][PreserveFirstFoundResourceTransformer] for specific files
90
92
- or write your own [`ResourceTransformer`][ResourceTransformer] to handle duplicates
91
93
- or mechanism similar.
92
-
4. Optionally, enable [`ShadowJar.failOnDuplicateEntries`][ShadowJar.failOnDuplicateEntries] to check duplicate entries in the final JAR.
93
-
5. Optionally, use [Diffuse](https://github.com/JakeWharton/diffuse) to diff the JARs.
94
+
95
+
Alternatively, you can follow these steps:
96
+
97
+
1. Set the default strategy to `EXCLUDE` or `FAIL`.
98
+
2. Apply your [`ResourceTransformer`][ResourceTransformer]s.
99
+
3. Bypass the duplicate entries which should be handled by the [`ResourceTransformer`][ResourceTransformer]s using
100
+
[`filesMatching`][Jar.filesMatching], [`filesNotMatching`][Jar.filesNotMatching], or [`eachFile`][Jar.eachFile] functions
101
+
to set their `duplicatesStrategy` to `INCLUDE` or `WARN`.
102
+
103
+
Optional steps:
104
+
105
+
- Enable [`ShadowJar.failOnDuplicateEntries`][ShadowJar.failOnDuplicateEntries] to check duplicate entries in the final JAR.
106
+
- Use [Diffuse](https://github.com/JakeWharton/diffuse) to diff the JARs.
107
+
108
+
Here are some examples:
109
+
110
+
=== "Kotlin"
111
+
112
+
```kotlin
113
+
tasks.shadowJar {
114
+
// Step 1.
115
+
duplicatesStrategy = DuplicatesStrategy.INCLUDE // Or WARN.
116
+
// Step 2.
117
+
mergeServiceFiles()
118
+
// Step 3. Using `filesNotMatching`:
119
+
filesNotMatching("META-INF/services/**") {
120
+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE // Or FAIL.
121
+
}
122
+
// Step 3. Using `PreserveFirstFoundResourceTransformer`:
Copy file name to clipboardExpand all lines: src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt
0 commit comments