Skip to content

Add ProGuardFilesResourceTransformer to merge R8/ProGuard rule files - #2196

Merged
Goooler merged 5 commits into
mainfrom
g/20260817/proguard-trans
Aug 17, 2026
Merged

Add ProGuardFilesResourceTransformer to merge R8/ProGuard rule files#2196
Goooler merged 5 commits into
mainfrom
g/20260817/proguard-trans

Conversation

@Goooler

@Goooler Goooler commented Aug 17, 2026

Copy link
Copy Markdown
Member

Closes #1696.


  • CHANGELOG's "Unreleased" section has been updated, if applicable.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ProGuardFilesResourceTransformer to merge META-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>
@Goooler
Goooler force-pushed the g/20260817/proguard-trans branch 2 times, most recently from f3c7d4a to 13f4e03 Compare August 17, 2026 08:25
@Goooler
Goooler force-pushed the g/20260817/proguard-trans branch from 13f4e03 to ed4a032 Compare August 17, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_PATTERN will also match and relocate dotted filenames like com.foo.jar (e.g., in -injars / -libraryjars directives). 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 *.pro files to avoid accidentally relocating/merging unrelated resources under that directory.
constructor(patternSet: PatternSet = PatternSet().include("META-INF/proguard/**")) :

@Goooler
Goooler enabled auto-merge (squash) August 17, 2026 08:53
@Goooler
Goooler merged commit 9e2e922 into main Aug 17, 2026
9 checks passed
@Goooler
Goooler deleted the g/20260817/proguard-trans branch August 17, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support merging and relocating ProGuard rules

2 participants