/proguard-services-mapper

A solution to fix obfuscated Java services after ProGuard has run.

Primary LanguageKotlinMIT LicenseMIT

ProGuard Service Mapper

GitHub license Maven Package Maven Central Sonatype Nexus (Snapshots) GitHub stars

This is a service mapper for the ProGuard Java bytecode obfuscator.

It fixes the issue that files in the META-INF/services directory are not renamed or adapted to the new class names.

It replaces the original Jar file with a new one that contains the renamed services.

It consists of the following modules:

ProGuard Service Mapper CLI

For convenience, the service mapper can be run from the command line. Withouth any additional arguments, it will print help information.

Usage

$ java -jar proguard-service-mapper-cli-<version>.jar -i <input-file> -m <mapping-file>

ProGuard Service Mapper Maven

This plugin is intended to be integrated into your Maven build process and run after the ProGuard Maven plugin.

Usage in Maven

<plugin>
  <groupId>com.github.gianttreelp.proguardservicesmapper</groupId>
  <artifactId>proguard-service-mapper-maven-plugin</artifactId>
  <version>1.2-SNAPSHOT</version> <!-- Update with the version you want to use, preferably the latest -->
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>map-proguard</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <input><!-- The obfuscated input file --></input>
    <mapping><!-- The mapping file from ProGuard --></mapping>
  </configuration>
</plugin>

ProGuard Service Mapper Gradle

This plugin is intended to be integrated into your Gradle build process and run after the ProGuard Gradle plugin.

Example usage in Gradle with the ProGuard Gradle plugin and the Shadow plugin

buildscript {
  dependencies {
    classpath("com.github.gianttreelp.proguardservicesmapper:proguard-services-mapper-gradle:1.2-SNAPSHOT")
  }   
}

register<com.github.gianttreelp.proguardservicesmapper.gradle.ProguardServicesMapperTask>("mapServices") {
  this.dependsOn("proguard")
  
  val shadowTask = project.tasks.shadowJar.orNull ?: throw IllegalStateException("No shadow jar task found")
  
  this.mappingFile.set(project.buildDir.resolve("mapping.txt"))
  this.inputFile.set(shadowTask.outputs.files.files.single().let {
    File(it.path.substringBeforeLast('.') + "-obf." + it.path.substringAfterLast('.'))
  })
}