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. }
  7. task minimizedJar(type: proguard.gradle.ProGuardTask, dependsOn: shadowJar) {
  8. injars "build/libs/my-application.jar"
  9. outjars "build/libs/my-application.min.jar"
  10. libraryjars System.properties.'java.home' + "/lib/rt.jar"
  11. printmapping "build/libs/my-application.map"
  12. ignorewarnings
  13. dontobfuscate
  14. dontoptimize
  15. dontwarn
  16. def keepClasses = [
  17. 'io.ktor.server.netty.EngineMain', // The EngineMain you use, netty in this case.
  18. 'kotlin.reflect.jvm.internal.**',
  19. 'io.ktor.samples.hello.HelloApplicationKt', // The class containing your module defined in the application.conf
  20. 'kotlin.text.RegexOption'
  21. ]
  22. for (keepClass in keepClasses) {
  23. keep access: 'public', name: keepClass, {
  24. method access: 'public'
  25. method access: 'private'
  26. }
  27. }
  28. }

note

Proguard - 图2

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