scala - Multiple executable jar files with different external dependencies from a single project with sbt-assembly -
i have single scala project built sbt using build.scala file. can use sbt-assembly generate single executable jar file project without problem. want generate multiple executable jar files, each file includes common set of internal , external base dependencies along different external dependencies.
is possible current version of sbt-assembly? in maven easy, 1 can define multiple profiles in pom, each generating separate jar, in sbt-assembly pass assembly settings project , haven't figured out way modify settings generate multiple jar files.
the concept of maven profile translates in sbt/ivy configuration. can define settings within configuration , have sbt-assembly generate 2 jars. can add librarydependency specific configuration adding % "config"
. this, requires project aware of configuration(s) upfront.
in build.sbt
(requires sbt 0.13.0 or above):
import assemblykeys._ val dispatch10 = config("dispatch10") extend(compile) val testdispatch10 = config("testdispatch10") extend(test) val dispatch11 = config("dispatch11") extend(compile) val testdispatch11 = config("testdispatch11") extend(test) val root = project.in(file(".")). configs(dispatch10, testdispatch10, dispatch11, testdispatch11). settings( name := "helloworld", organization := "com.eed3si9n", scalaversion := "2.10.2", compile in test := inc.analysis.empty, compile in compile := inc.analysis.empty, librarydependencies ++= seq( "net.databinder.dispatch" %% "dispatch-core" % "0.10.0" % "dispatch10,testdispatch10", "net.databinder.dispatch" %% "dispatch-core" % "0.11.0" % "dispatch11,testdispatch11", "org.specs2" %% "specs2" % "2.2" % "test", "com.github.scopt" %% "scopt" % "3.0.0" ) ). settings(inconfig(dispatch10)(classpaths.configsettings ++ defaults.configtasks ++ baseassemblysettings ++ seq( test := (test in testdispatch10).value, test in assembly := test.value, assemblydirectory in assembly := cachedirectory.value / "assembly-dispatch10", jarname in assembly := name.value + "-assembly-dispatch10_" + version.value + ".jar" )): _*). settings(inconfig(testdispatch10)(classpaths.configsettings ++ defaults.configtasks ++ defaults.testtasks ++ seq( internaldependencyclasspath := seq((classdirectory in dispatch10).value).classpath )): _*). settings(inconfig(dispatch11)(classpaths.configsettings ++ defaults.configtasks ++ baseassemblysettings ++ seq( test := (test in testdispatch11).value, test in assembly := test.value, assemblydirectory in assembly := cachedirectory.value / "assembly-dispatch11", jarname in assembly := name.value + "-assembly-dispatch11_" + version.value + ".jar" )): _*). settings(inconfig(testdispatch11)(classpaths.configsettings ++ defaults.configtasks ++ defaults.testtasks ++ seq( internaldependencyclasspath := seq((classdirectory in dispatch11).value).classpath )): _*)
to run assembly task within configuration, you'd say:
> dispatch11:assembly [info] helloworldspec [info] [info] 'hello world' string should [info] + contain 11 characters [info] [info] total specification helloworldspec [info] finished in 17 ms [info] 1 examples, 0 failure, 0 error [info] passed: total 1, failed 0, errors 0, passed 4 [info] including: scopt_2.10-3.0.0.jar [info] including: slf4j-api-1.6.2.jar [info] including: netty-3.6.3.final.jar [info] including: scala-library.jar [info] including: async-http-client-1.7.16.jar [info] including: dispatch-core_2.10-0.11.0.jar [warn] merging 'meta-inf/notice.txt' strategy 'rename' [warn] merging 'meta-inf/license' strategy 'rename' [warn] merging 'meta-inf/license.txt' strategy 'rename' [warn] merging 'meta-inf/manifest.mf' strategy 'discard' [warn] strategy 'discard' applied file [warn] strategy 'rename' applied 3 files [info] checking every *.class/*.jar file's sha-1. [info] sha-1: xxxxxxxxxxxx [info] packaging /users/foo/helloworld/target/scala-2.10/helloworld-assembly-dispatch11_0.1-snapshot.jar ... [info] done packaging.
Comments
Post a Comment