Add ProGuardFilesResourceTransformer to merge R8/ProGuard rule files - #2196
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds first-class support in Shadow for merging dependency-provided R8/ProGuard rules shipped as resources, aligning with the feature request in #1696.
Changes:
- Introduces
ProGuardFilesResourceTransformerto mergeMETA-INF/proguard/**rule resources and relocate matched class/package tokens within rules. - Adds unit + functional test coverage for matching, merging behavior, and relocation behavior.
- Updates documentation and public API surface to include the new transformer.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ProGuardFilesResourceTransformer.kt | New transformer to merge and relocate ProGuard/R8 rule files under META-INF/proguard/**. |
| src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ProGuardFilesResourceTransformerTest.kt | Unit tests for default/custom path matching + merge/relocation behavior. |
| src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ProGuardFilesResourceTransformerTest.kt | Functional coverage ensuring merged jar outputs contain expected entries and relocated rules. |
| src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/DuplicatesStrategyCheckerTest.kt | Updates transformer counts/invocations to account for the new transformer. |
| docs/configuration/merging/README.md | Adds user-facing docs + transformer list/link for the new transformer. |
| docs/changes/README.md | Changelog entry for the new transformer feature. |
| api/shadow.api | Records the new public API class in the API dump. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
f3c7d4a to
13f4e03
Compare
13f4e03 to
ed4a032
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ProGuardFilesResourceTransformer.kt:67
CLASS_PATTERNwill also match and relocate dotted filenames likecom.foo.jar(e.g., in-injars/-libraryjarsdirectives). Relocating those file paths would change the meaning of the ProGuard config. Consider skipping relocation for known file-path directives (or otherwise tightening the match so only class/package tokens are relocated).
fun Iterable<Relocator>.relocateRuleLine(line: String): String {
return when {
line.isBlank() || line.trimStart().startsWith("#") -> line
else ->
CLASS_PATTERN.replace(line) { matchResult ->
src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ProGuardFilesResourceTransformer.kt:23
- The default include pattern is
META-INF/proguard/**, which will also match non-rule resources (and potentially directories). Since this transformer is intended for rule files (issue scope calls out**.pro), consider restricting the default include to only*.profiles to avoid accidentally relocating/merging unrelated resources under that directory.
constructor(patternSet: PatternSet = PatternSet().include("META-INF/proguard/**")) :
Closes #1696.