Reputation: 39366
I have a single source tree from which I might build two different jars; call them JarA and JarB.
I am using the sbt proguard plugin to run each jar through proguard. This plugin creates a task key called proguard
.
I would like to make two task keys, say proguardA
and proguardB
, that build the respective jars. I have defined these task keys in project/Build.scala.
But, how do I use a different set of proguard options for each task? That is, how can I use a different value for the setting proguardOptions
?
I have tried various permutations of task-scoped settings such as
proguardA <<= proguard in proguardA
proguardSettings in (proguard in proguardA) <<= ...
proguardSettings in proguardA <<= ...
etc
But none of these have taken effect.
Upvotes: 4
Views: 255
Reputation: 95654
There are several ways to skin this cat, but I'd define two configurations in build.scala:
val ProguardA = config("proguarda") extend(Compile)
val ProguardB = config("proguardb") extend(Compile)
This will let you have a whole set of settings outside of Compile
. As xsbt-proguard-plugin currently hardcodes the option to Compile
configuration, we need to fix the proguard
task.
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)
}
You can now run it as proguarda:proguard
or make a task proguarda
that depends on proguard in ProguardA
. Also you have to change the minJarPath
or run clean
each time to avoid cache picking up a wrong jar.
Upvotes: 1