Align with Stratum-default + per-mod overrides: do not ship a full duplicate ruleset beyond proguard-baseline.pro; extras go in proguard-mod.pro only.
96 lines
4.0 KiB
Groovy
96 lines
4.0 KiB
Groovy
// 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
|
|
}
|
|
}
|