Proguard

This module allows Proguard to be used in Mill builds. ProGuard is a Java class file shrinker, optimizer, obfuscator, and preverifier.

By default, all four steps - shrink, optimize, obfuscate, verify - are run, but this can be configured through task options. Any additional options can be specified as a list of strings with additionalOptions. The full list of proguard options can be found here.

The output of assembly is used as the input jar and the output is written to out.jar in the dest folder.

The stdout and stderr from the proguard command can be found under the dest folder.

The only default entrypoint is the main class (i.e. finalMainClass task). Additional entrypoints can be configured using additionalOptions as well.

Here is a simple example:

build.sc
import $ivy.`com.lihaoyi::mill-contrib-proguard:`
import contrib.proguard._

object foo extends ScalaModule with Proguard {
  def scalaVersion = "2.13.8"

  override def shrink: T[Boolean] = T { true }
  override def optimize: T[Boolean] = T { false }
  override def obfuscate: T[Boolean] = T { false }

  // https://github.com/Guardsquare/proguard/releases
  override def proguardVersion = T("7.3.2")

  // tell Proguard where to enter your app, so it can optimise outwards from there
  override def entryPoint = T {
    s"""|-keep public class myProject.main.myApp {
        |  public ReturnType main(ParamTypeA, ParamTypeB);
        |}
        |""".stripMargin
  }

  // customise to be as narrow/wide as your application requires
  override def additionalOptions = Seq (
    "-keep class myProject.main.myApp { *; }",
    "-keep class Scala.Symbol { *; };
  )
}