Skip to content

Instantly share code, notes, and snippets.

@CorgiTaco
Last active December 31, 2023 09:21
Show Gist options
  • Save CorgiTaco/3293ac50e21b73a19618e7826c61f5fc to your computer and use it in GitHub Desktop.
Save CorgiTaco/3293ac50e21b73a19618e7826c61f5fc to your computer and use it in GitHub Desktop.
Proguard task for a Forge Minecraft mod. Tested against Forge 1.18.2. Setting up Proguard in gradle can be found here: https://www.guardsquare.com/manual/setup/gradle
tasks.register('proguard', ProGuardTask) {
dependsOn tasks.jar
keep(["allowobfuscation": true], "public class ${project.group}.** { *; }")
keep(["allowobfuscation": false], "public class ${project.group}.mixin.** { *; }") //TODO: Update mixin config in jar
optimizationpasses(10)
keepattributes("*Annotation*")
verbose()
printmapping(project.layout.buildDirectory.file("proguard/mappings.map"))
configurations.runtimeClasspath.getResolvedConfiguration().getFiles().each { File file ->
if (file.isFile() && file.getName().endsWith('.jar')) {
libraryjars(file.getPath())
}
}
// Automatically handle the Java version of this build.
if (System.getProperty('java.version').startsWith('1.')) {
// Before Java 9, the runtime classes were packaged in a single jar file.
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
} else {
// As of Java 9, the runtime classes are packaged in modular jmod files.
libraryjars "${System.getProperty('java.home')}/jmods/java.base.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
//libraryjars "${System.getProperty('java.home')}/jmods/....."
}
injars tasks.jar.outputs.files.singleFile
outjars(layout.buildDirectory.file("libs/${archivesBaseName}-minified.jar"))
reobfJar.input.fileValue(layout.buildDirectory.file("libs/${archivesBaseName}-minified.jar").get().asFile);
finalizedBy('reobfJar')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment