feat(build): try proguard again.

This commit is contained in:
huanghongxun
2021-09-30 19:38:51 +08:00
parent 33aeb24dbe
commit 57cb98f13a

View File

@@ -6,6 +6,8 @@ buildscript {
dependencies { dependencies {
classpath 'org.tukaani:xz:1.8' classpath 'org.tukaani:xz:1.8'
classpath 'org.glavo:pack200:0.3.0' classpath 'org.glavo:pack200:0.3.0'
classpath 'com.guardsquare:proguard-gradle:7.1.0' // The ProGuard Gradle plugin.
} }
} }
@@ -162,6 +164,41 @@ shadowJar {
} }
} }
task proguard(type: proguard.gradle.ProGuardTask) {
dependsOn shadowJar
injars shadowJar
outjars "${buildDir}/libs/${project.name}-${project.version}-proguard.jar"
dontobfuscate
dontoptimize
keep 'public class org.jackhuang.**'
keep 'public class org.slf4j.**'
dontwarn 'com.nqzero.**'
dontwarn 'org.slf4j.**'
dontwarn 'org.jackhuang.hmcl.util.Pack200Utils'
adaptclassstrings
// next block taken verbatim from Proguard's documentation examples:
libraryjars files(configurations.compileClasspath.collect())
keepattributes 'SourceFile,LineNumberTable'
// 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"
libraryjars "${System.getProperty('java.home')}/lib/ext/jfxrt.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'
// }
}
def createExecutable(String suffix, String header) { def createExecutable(String suffix, String header) {
def output = new File(jar.archivePath.parentFile, jar.archivePath.name[0..-4] + suffix) def output = new File(jar.archivePath.parentFile, jar.archivePath.name[0..-4] + suffix)
output.bytes = new File(project.projectDir, header).bytes output.bytes = new File(project.projectDir, header).bytes