Proguard

note

Proguard - 图1

This help topic is in development and will be updated in the future.

If you have some restrictions on your JAR size (for example when deploying a free application to heroku, you can use proguard to shrink it. If you are using gradle, it is pretty straightforward to use the proguard-gradle plugin. You only have to remember to keep: your main module method, the EngineMain class, and the Kotlin reflect classes. You can then fine-tune it as required:

1. buildscript {
2. ext.proguard_version = '6.0.1'
3. dependencies {
4. classpath "net.sf.proguard:proguard-gradle:$proguard_version"
5. }
6. }

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

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

25. for (keepClass in keepClasses) {
26. keep access: 'public', name: keepClass, {
27. method access: 'public'
28. method access: 'private'
29. }
30. }
31. }

note

Proguard - 图2

You have a full example on: <https://github.com/ktorio/ktor-samples/tree/1.3.0/other/proguard>