https://github.com/sgtsilvio/gradle-proguard
Gradle plugin to ease using ProGuard
https://github.com/sgtsilvio/gradle-proguard
gradle-plugin obfuscation proguard
Last synced: over 1 year ago
JSON representation
Gradle plugin to ease using ProGuard
- Host: GitHub
- URL: https://github.com/sgtsilvio/gradle-proguard
- Owner: SgtSilvio
- License: apache-2.0
- Created: 2021-05-17T21:04:57.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-14T16:01:09.000Z (over 1 year ago)
- Last Synced: 2025-03-16T02:26:15.358Z (over 1 year ago)
- Topics: gradle-plugin, obfuscation, proguard
- Language: Kotlin
- Homepage:
- Size: 433 KB
- Stars: 38
- Watchers: 1
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gradle ProGuard Plugin
[](https://plugins.gradle.org/plugin/io.github.sgtsilvio.gradle.proguard)
[](LICENSE)
[](https://github.com/SgtSilvio/gradle-proguard/actions/workflows/check.yml?query=branch%3Amain)
Gradle plugin to ease using ProGuard.
This implementation differs from the official ProGuard gradle plugin in the following points:
- ProGuard and the Gradle daemon are decoupled:
- How: Runs ProGuard in a separate process (via the command line interface) instead of in the Gradle daemon
- Why: ProGuard tends to use a lot of memory which can expire the daemon or even require increasing its heap.
- ProGuard's and this plugin's version are decoupled:
- How: The Proguard base dependency is added to the `proguardClasspath` configuration and can be customized.
Additionally, only the ProGuard configuration parameters that deal with files are modelled as Gradle input and
output properties, because these are the only ones necessary for up-to-date checks and caching.
All other (maybe ProGuard version specific) configurations can be passed as string arguments via `rules`.
- Why: Using a bug fix in either ProGuard or this plugin should not need an update of the other tool.
- Gradle compatibility:
- How: Using proper input and output annotations with path sensitivity to benefit from the build cache regardless
of where the project is located.
- Why: Taking full advantages of Gradle and being future-proof.
- This plugin is completely Android agnostic
- How: No dependency on any Android artifacts.
- Why: ProGuard can be used for any JVM program.
## How to Use
```kotlin
plugins {
java
id("io.github.sgtsilvio.gradle.proguard") version "0.8.0"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
//...
val proguardJar by tasks.registering(proguard.taskClass) {
addInput {
classpath.from(tasks.shadowJar)
}
addOutput {
archiveFile.set(base.libsDirectory.file("${project.name}-${project.version}-proguarded.jar"))
}
jdkModules.add("java.base")
mappingFile.set(base.libsDirectory.file("${project.name}-${project.version}-mapping.txt"))
rules.addAll(
"-dontoptimize",
"-dontwarn !org.example.**",
"-flattenpackagehierarchy",
"-keep class org.example.Main { public static void main(java.lang.String[]); }",
"-keepattributes Signature,InnerClasses,*Annotation*"
)
}
```
## Requirements
- Gradle 6.7 or higher
## Configuration
### ProGuard Version
You can add a custom proguard dependency to the `proguardClasspath` configuration.
The default dependency is overwritten if you specify any dependency for this configuration.
```kotlin
dependencies {
proguardClasspath("com.guardsquare:proguard-base:7.2.2")
}
```
### ProGuard Process
The ProGuard task class extends Gradle's `JavaExec` task class, so all of its properties
(Java version, heap size, jvm arguments, system properties, environment variables, classpath, main class, debugging)
can be used to configure the ProGuard process.
```kotlin
val proguardJar by tasks.registering(proguard.taskClass) {
//...
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
})
maxHeapSize = "2G"
}
```