Last active
January 23, 2025 04:03
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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