Skip to content

Commit b90fd80

Browse files
committed
Add initial implementation of the ProGuard plugin
1 parent 2a741ab commit b90fd80

File tree

12 files changed

+837
-0
lines changed

12 files changed

+837
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
.gradle/

packages/proguard-plugin/README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Proguard Plugin
2+
3+
A Gradle plugin that uploads ProGuard/R8 obfuscation mapping files to the [Faststats](https://faststats.dev) sourcemaps
4+
API for stacktrace deobfuscation.
5+
6+
## Installation
7+
8+
Add the plugin to your project's `build.gradle.kts`:
9+
10+
```kotlin
11+
plugins {
12+
id("dev.faststats.proguard-mappings-upload") version "0.1.0"
13+
}
14+
```
15+
16+
Or in Groovy (`build.gradle`):
17+
18+
```groovy
19+
plugins {
20+
id 'dev.faststats.proguard-mappings-upload' version '0.1.0'
21+
}
22+
```
23+
24+
## Configuration
25+
26+
### With a custom ProGuard task
27+
28+
```kotlin
29+
mappingsUpload {
30+
authToken.set("your-auth-token")
31+
proguardTask.set(tasks.getByName("proguard"))
32+
mappingFiles.from(layout.buildDirectory.file("proguard/mapping.txt"))
33+
}
34+
```
35+
36+
Setting `proguardTask` ensures the upload task runs after ProGuard finishes. You still need to point `mappingFiles` to
37+
the actual mapping file location (matching your `printmapping` config).
38+
39+
### Android Projects
40+
41+
```kotlin
42+
mappingsUpload {
43+
authToken.set("your-auth-token")
44+
}
45+
```
46+
47+
The plugin automatically detects Android R8/ProGuard mapping file outputs when the Android Gradle Plugin is present. No
48+
additional configuration is needed.
49+
50+
### All Options
51+
52+
```kotlin
53+
mappingsUpload {
54+
// Required – API auth token. Falls back to FASTSTATS_AUTH_TOKEN env var.
55+
authToken.set("your-auth-token")
56+
57+
// Optional – API endpoint (default: https://sourcemaps.faststats.dev/api/sourcemaps)
58+
endpoint.set("https://sourcemaps.faststats.dev/api/sourcemaps")
59+
60+
// Optional – Build identifier (default: project.version)
61+
buildId.set("1.2.3")
62+
63+
// Optional – Task that produces the mapping file (adds a dependsOn)
64+
proguardTask.set(tasks.getByName("proguard"))
65+
66+
// Optional – Mapping files to upload (default: build/obfuscation-mappings.txt)
67+
mappingFiles.from(layout.buildDirectory.file("proguard/mapping.txt"))
68+
}
69+
```
70+
71+
## Usage
72+
73+
Run the upload task:
74+
75+
```bash
76+
./gradlew uploadProguardMappings
77+
```
78+
79+
Or chain it after your obfuscation task:
80+
81+
```bash
82+
./gradlew proguard uploadProguardMappings
83+
```
84+
85+
## CI Configuration
86+
87+
### GitHub Actions
88+
89+
```yaml
90+
name: Build & Upload Mappings
91+
92+
on:
93+
push:
94+
branches: [ main ]
95+
96+
jobs:
97+
build:
98+
runs-on: ubuntu-latest
99+
steps:
100+
- uses: actions/checkout@v4
101+
102+
- uses: actions/setup-java@v4
103+
with:
104+
distribution: temurin
105+
java-version: 17
106+
107+
- name: Build & Upload
108+
run: ./gradlew proguard uploadProguardMappings
109+
env:
110+
FASTSTATS_AUTH_TOKEN: ${{ secrets.FASTSTATS_AUTH_TOKEN }}
111+
```
112+
113+
### GitLab CI
114+
115+
```yaml
116+
build:
117+
stage: build
118+
script:
119+
- ./gradlew proguard uploadProguardMappings
120+
variables:
121+
FASTSTATS_AUTH_TOKEN: $FASTSTATS_AUTH_TOKEN
122+
```
123+
124+
## How It Works
125+
126+
1. The plugin looks for mapping files added via `mappingFiles.from(...)`, or auto-detected Android build outputs.
127+
2. If `proguardTask` is set, the upload task automatically depends on it.
128+
3. Uses `project.version` as the `buildId` by default.
129+
4. Each mapping file is split by class sections and uploaded in batches of up to 50MB, ensuring no class mapping is
130+
split across batches.
131+
132+
## Requirements
133+
134+
- Gradle 7.0+
135+
- JDK 11+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
plugins {
2+
kotlin("jvm") version "2.3.20"
3+
id("java-gradle-plugin")
4+
id("maven-publish")
5+
}
6+
7+
group = "dev.faststats"
8+
version = "0.1.0"
9+
10+
repositories {
11+
mavenCentral()
12+
google()
13+
}
14+
15+
dependencies {
16+
implementation("com.google.code.gson:gson:2.13.1")
17+
compileOnly("com.android.tools.build:gradle:8.7.3")
18+
}
19+
20+
java {
21+
sourceCompatibility = JavaVersion.VERSION_11
22+
targetCompatibility = JavaVersion.VERSION_11
23+
}
24+
25+
kotlin {
26+
jvmToolchain(11)
27+
}
28+
29+
gradlePlugin {
30+
plugins {
31+
create("proguardMappingsUpload") {
32+
id = "dev.faststats.proguard-mappings-upload"
33+
implementationClass = "dev.faststats.proguard.FastStatsProguardPlugin"
34+
displayName = "Faststats ProGuard Mapping Upload Plugin"
35+
description = "Uploads ProGuard/R8 obfuscation mapping files to the FastStats sourcemaps API"
36+
}
37+
}
38+
}
39+
40+
publishing {
41+
publications.create<MavenPublication>("maven") {
42+
// pom.url.set("https://docs.faststats.dev/serviceio")
43+
pom.scm {
44+
val repository = "FastStats-dev/sourcemaps"
45+
url.set("https://github.com/$repository/tree/main/packages/proguard-plugin")
46+
connection.set("scm:git:git://github.com/$repository.git")
47+
developerConnection.set("scm:git:ssh://github.com/$repository.git")
48+
}
49+
from(components["java"])
50+
}
51+
repositories.maven {
52+
val branch = if (version.toString().contains("-pre")) "snapshots" else "releases"
53+
url = uri("https://repo.thenextlvl.net/$branch")
54+
credentials {
55+
username = System.getenv("REPOSITORY_USER")
56+
password = System.getenv("REPOSITORY_TOKEN")
57+
}
58+
}
59+
}
47.8 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)