Proguard

预计阅读时间:1分钟

如果您对JAR大小有一些限制(例如,在将免费应用程序部署到heroku时 ),则可以使用proguard缩小它. 如果使用gradle,则使用proguard-gradle插件非常简单. 您只需要记住:主模块方法,EngineMain类和Kotlin反映类. 然后,您可以根据需要对其进行微调:

build.gradle
buildscript {
    ext.proguard_version = '6.0.1'
    dependencies {
        classpath "net.sf.proguard:proguard-gradle:$proguard_version"
    }
}

task minimizedJar(type: proguard.gradle.ProGuardTask, dependsOn: shadowJar) {
    injars "build/libs/my-application.jar"
    outjars "build/libs/my-application.min.jar"
    libraryjars System.properties.'java.home' + "/lib/rt.jar"
    printmapping "build/libs/my-application.map"
    ignorewarnings
    dontobfuscate
    dontoptimize
    dontwarn

    def keepClasses = [
            'io.ktor.server.netty.EngineMain', // The EngineMain you use, netty in this case.
            'kotlin.reflect.jvm.internal.**',
            'io.ktor.samples.hello.HelloApplicationKt', // The class containing your module defined in the application.conf
            'kotlin.text.RegexOption'
    ]

    for (keepClass in keepClasses) {
        keep access: 'public', name: keepClass, {
            method access: 'public'
            method access: 'private'
        }
    }
}

 

您在以下位置有完整的示例: https : //github.com/ktorio/ktor-samples/tree/master/other/proguard

by  ICOPY.SITE