有几种方法可以给这只猫换皮,但我会在 build.scala 中定义两种配置:
val ProguardA = config("proguarda") extend(Compile)
val ProguardB = config("proguardb") extend(Compile)
这将使您在Compile
. 由于 xsbt-proguard-plugin 当前对Compile
配置选项进行硬编码,我们需要修复该proguard
任务。
import sbt._
import Keys._
import ProguardPlugin._
object Builds extend Build {
val ProguardA = config("proguarda") extend(Compile)
val ProguardB = config("proguardb") extend(Compile)
val xProguardArgs = TaskKey[List[String]]("x-proguard-args")
val appSettings = Defaults.defaultSettings ++
inConfig(ProguardA)(proguardSettings ++ Seq(
proguard <<= (packageBin in Compile, xProguardArgs, baseDirectory) map { (_, args, bd) => proguardTask(args, bd) },
xProguardArgs <<= proguardArgsTask,
proguardOptions := Seq(keepMain("Test"))
)) ++
inConfig(ProguardB)(proguardSettings ++ Seq(
proguard <<= (packageBin in Compile, xProguardArgs, baseDirectory) map { (_, args, bd) => proguardTask(args, bd) },
xProguardArgs <<= proguardArgsTask,
proguardOptions := Seq(keepAllScala),
minJarPath <<= (crossTarget, projectID, artifact, scalaVersion, artifactName) { (t, module, a, sv, toString) => t / toString(ScalaVersion(sv, CrossVersion binaryScalaVersion sv), module.copy(revision = module.revision + ".min-b"), a) asFile }
)) ++
Seq(
// name := "foo",
// libraryDependencies ++= appDependencies
)
lazy val app = Project("app", file("."), settings = appSettings)
}
您现在可以将其作为proguarda:proguard
依赖proguarda
于proguard in ProguardA
. 此外,您必须每次更改minJarPath
或运行clean
以避免缓存拾取错误的 jar。