Compare commits
1
Commits
main
...
chore/proguard
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0296c7143b |
No files matched your search
@@ -21,3 +21,5 @@ eclipse/
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
build/proguard/
|
||||
*.proguard-mapping.txt
|
||||
@@ -2,3 +2,6 @@ plugins { id 'com.gtnewhorizons.gtnhconvention' }
|
||||
|
||||
version = providers.gradleProperty('modVersion').get()
|
||||
|
||||
|
||||
// Standalone ProGuard (non-Stratum): baseline + optional proguard-mod.pro
|
||||
apply from: 'proguard.gradle'
|
||||
@@ -0,0 +1,70 @@
|
||||
# Stratum Forge ProGuard baseline (1.7.10 / GTNH).
|
||||
# Injected by stratum.init.gradle — do not pretend string encryption exists here.
|
||||
-dontoptimize
|
||||
-dontpreverify
|
||||
-allowaccessmodification
|
||||
|
||||
-keepattributes Signature,InnerClasses,EnclosingMethod,*Annotation*,RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,AnnotationDefault,SourceFile,LineNumberTable
|
||||
|
||||
# Forge @Mod entry (FML 1.7.10 + newer)
|
||||
-keep @cpw.mods.fml.common.Mod class * { *; }
|
||||
-keep @net.minecraftforge.fml.common.Mod class * { *; }
|
||||
-keepclassmembers class * {
|
||||
@cpw.mods.fml.common.Mod$EventHandler *;
|
||||
@cpw.mods.fml.common.Mod$Instance *;
|
||||
@cpw.mods.fml.common.SidedProxy *;
|
||||
@net.minecraftforge.fml.common.Mod$EventHandler *;
|
||||
@net.minecraftforge.fml.common.Mod$Instance *;
|
||||
@net.minecraftforge.fml.common.SidedProxy *;
|
||||
}
|
||||
|
||||
# Mixin
|
||||
-keep @org.spongepowered.asm.mixin.Mixin class * { *; }
|
||||
-keep @org.spongepowered.asm.mixin.Mixin class *$* { *; }
|
||||
-keepclassmembers class * {
|
||||
@org.spongepowered.asm.mixin.Shadow *;
|
||||
@org.spongepowered.asm.mixin.Overwrite *;
|
||||
@org.spongepowered.asm.mixin.Unique *;
|
||||
@org.spongepowered.asm.mixin.injection.Inject *;
|
||||
@org.spongepowered.asm.mixin.injection.Redirect *;
|
||||
@org.spongepowered.asm.mixin.injection.ModifyVariable *;
|
||||
@org.spongepowered.asm.mixin.injection.ModifyArg *;
|
||||
@org.spongepowered.asm.mixin.injection.ModifyArgs *;
|
||||
@org.spongepowered.asm.mixin.injection.ModifyConstant *;
|
||||
}
|
||||
|
||||
# Coremod / JNI
|
||||
-keep class * implements cpw.mods.fml.relauncher.IFMLLoadingPlugin { *; }
|
||||
-keep class * implements net.minecraftforge.fml.relauncher.IFMLLoadingPlugin { *; }
|
||||
-keepclasseswithmembernames,includedescriptorclasses class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
# Enums / Serializable
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
-keepclassmembers class * implements java.io.Serializable {
|
||||
static final long serialVersionUID;
|
||||
private static final java.io.ObjectStreamField[] serialPersistentFields;
|
||||
private void writeObject(java.io.ObjectOutputStream);
|
||||
private void readObject(java.io.ObjectInputStream);
|
||||
java.lang.Object writeReplace();
|
||||
java.lang.Object readResolve();
|
||||
}
|
||||
|
||||
# Kotlin metadata (harmless if unused)
|
||||
-keep class kotlin.Metadata { *; }
|
||||
-keepclassmembers class **$WhenMappings { <fields>; }
|
||||
-keepclassmembers class **$Companion { *; }
|
||||
|
||||
# Missing MC/Forge at obfuscation time
|
||||
-dontwarn net.minecraft.**
|
||||
-dontwarn cpw.mods.**
|
||||
-dontwarn net.minecraftforge.**
|
||||
-dontwarn org.spongepowered.asm.**
|
||||
-dontwarn scala.**
|
||||
-dontwarn groovy.**
|
||||
-dontwarn javax.**
|
||||
-dontwarn sun.**
|
||||
@@ -0,0 +1,3 @@
|
||||
# Per-mod overrides (Mixin / @Mod FQN / coremod). Shared baseline is proguard-baseline.pro.
|
||||
-keep class com.pengu.thaumcraft.additions.core.TACore { *; }
|
||||
-keep class com.pengu.thaumcraft.additions.preloader.ThaumicALoaderContainer { *; }
|
||||
@@ -0,0 +1,95 @@
|
||||
// Minimal standalone ProGuard wiring for Forge mods that are NOT on Stratum.
|
||||
// Stratum layers should NOT use this file — enable stratum.proguard instead.
|
||||
// Layout: proguard-baseline.pro (shared rules) + optional proguard-mod.pro (overrides only).
|
||||
|
||||
configurations {
|
||||
proguardPath
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
proguardPath 'com.guardsquare:proguard-base:7.4.2'
|
||||
}
|
||||
|
||||
def pgDir = file("${buildDir}/proguard")
|
||||
def baseline = rootProject.file('proguard-baseline.pro')
|
||||
if (!baseline.exists()) baseline = file('proguard-baseline.pro')
|
||||
def modOverride = rootProject.file('proguard-mod.pro')
|
||||
if (!modOverride.exists()) modOverride = file('proguard-mod.pro')
|
||||
|
||||
task proguardJar(type: JavaExec) {
|
||||
group = 'build'
|
||||
description = 'Shrink/obfuscate jar (standalone baseline + optional proguard-mod.pro)'
|
||||
dependsOn tasks.matching { it.name == 'jar' }
|
||||
classpath = configurations.proguardPath
|
||||
if (hasProperty('mainClass')) {
|
||||
try { mainClass.set('proguard.ProGuard') } catch (Throwable t) { main = 'proguard.ProGuard' }
|
||||
} else {
|
||||
main = 'proguard.ProGuard'
|
||||
}
|
||||
outputs.dir pgDir
|
||||
|
||||
doFirst {
|
||||
if (!baseline.exists()) {
|
||||
throw new GradleException('Missing proguard-baseline.pro (standalone non-Stratum mods)')
|
||||
}
|
||||
pgDir.mkdirs()
|
||||
def jarTask = tasks.findByName('jar')
|
||||
if (jarTask == null) throw new GradleException('proguardJar requires a jar task')
|
||||
def inJar = jarTask.hasProperty('archiveFile') ? jarTask.archiveFile.get().asFile : jarTask.archivePath
|
||||
if (!inJar.exists()) throw new GradleException("Input jar missing: ${inJar}")
|
||||
def outJar = new File(pgDir, inJar.name.replace('.jar', '-proguard.jar'))
|
||||
def conf = new File(pgDir, 'proguard-generated.conf')
|
||||
def lines = [
|
||||
"-injars '${inJar.absolutePath}'",
|
||||
"-outjars '${outJar.absolutePath}'",
|
||||
"-include '${baseline.absolutePath}'",
|
||||
"-printmapping '${new File(pgDir, 'mapping.txt').absolutePath}'",
|
||||
"-printseeds '${new File(pgDir, 'seeds.txt').absolutePath}'",
|
||||
"-printusage '${new File(pgDir, 'usage.txt').absolutePath}'",
|
||||
]
|
||||
if (modOverride.exists()) {
|
||||
lines.add("-include '${modOverride.absolutePath}'")
|
||||
}
|
||||
def javaHome = System.getProperty('java.home')
|
||||
def rt = file("${javaHome}/lib/rt.jar")
|
||||
def rtJre = file("${javaHome}/../lib/rt.jar")
|
||||
if (rt.exists()) lines.add("-libraryjars '${rt.absolutePath}'")
|
||||
else if (rtJre.exists()) lines.add("-libraryjars '${rtJre.absolutePath}'")
|
||||
else {
|
||||
def jmod = file("${javaHome}/jmods/java.base.jmod")
|
||||
if (jmod.exists()) lines.add("-libraryjars '${jmod.absolutePath}'(!**.jar;!module-info.class)")
|
||||
}
|
||||
try {
|
||||
configurations.compileClasspath.files.findAll { it.name.endsWith('.jar') }.each { f ->
|
||||
if (f.absolutePath != inJar.absolutePath) lines.add("-libraryjars '${f.absolutePath}'")
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
try {
|
||||
configurations.compile.files.findAll { it.name.endsWith('.jar') }.each { f ->
|
||||
if (f.absolutePath != inJar.absolutePath) lines.add("-libraryjars '${f.absolutePath}'")
|
||||
}
|
||||
} catch (Throwable ignored2) { /* FG1 */ }
|
||||
}
|
||||
conf.text = lines.join('\n') + '\n'
|
||||
args '-include', conf.absolutePath
|
||||
ext.pgOut = outJar
|
||||
ext.pgIn = inJar
|
||||
}
|
||||
doLast {
|
||||
def outJar = ext.pgOut as File
|
||||
def inJar = ext.pgIn as File
|
||||
if (!outJar.exists()) throw new GradleException("proguardJar produced no output: ${outJar}")
|
||||
java.nio.file.Files.copy(outJar.toPath(), inJar.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
def assemble = tasks.findByName('assemble')
|
||||
if (assemble != null && (project.hasProperty('tdlmProguard') || project.findProperty('tdlm.proguard') == 'true')) {
|
||||
assemble.dependsOn proguardJar
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user