How to use sbt native packager with subprojects (sbt 0.13)

I have an sbt project with many subprojects and external library dependencies. build.sbt as follows:

 val extlib1 = "xy.xxx" % "lib1" % "1.0+" val extlib2 = "xy.yyy" % "lib2" % "1.0+" val extlib3 = "xy.zzz" % "lib3" % "1.0+" lazy val core=project settings ( name:="cor", libraryDependencies++=Seq(extlib1) ) lazy val servercore=project settings ( name:="srvcore", libraryDependencies++=Seq(extlib1,extlib2) ) dependsOn(core) lazy val masterserver=project settings ( name:="mastersrv", mainClass:=Some("masterserver") ) dependsOn(servercore) lazy val otherserver=project settings ( name:="othersrv", libraryDependencies++=Seq(extlib3), mainClass:=Some("otherserver") ) dependsOn(servercore) // Only for aggregating the builds of the subprojects lazy val root=project in file(".") settings(name:="proj") aggregate( core,servercore,masterserver,otherserver ) 

Thus, in fact, the project creates several programs ("masterserver", "othererver"), which depend on external libraries and a subset of the subprojects of the project itself.

I want to have the full set of JARs needed to run the main server or another server shared for each. So, I would like to have, for example, masterserver/target/<whatever> containing

 mastersrv.jar srvcore.jar (needed by mastersrv.jar) cor.jar (needed by srvcore.jar) lib1.jar (needed by mastersrv and srvcore) lib2.jar (needed by srvcore) <whatever>.jar (further libs needed by lib1 or lib2) 

and a otherserver/target/<whatever> with similar content (it should also add lib3.jar , since this is necessary for othersrv.jar .

How to do it? Can I accomplish this with my own package? The stage output in the root project does nothing (because there is no mailClass ?). Issuing masterserver/state gives an error message

 > masterserver/stage [error] No such setting/task [error] masterserver/stage [error] ^ 

I must admit that I do not understand from the documentation of the plugin of the native packer. How can I archive what I want?

Edit: Of course, I am not attached to a directory file. If I get several ZIP files in the main target directory, this is ok too. I only want to have all the subproject dependencies in one place.

Edit 2: Ok, I found out that Play! The framework does exactly what I want. And for this he uses his own sbt package. How can I archive recursive universal packaging of subprojects in non-sbt projects that use Java as a programming language?

+6
source share
1 answer

Well, the answer was pretty straight forward as soon as I checked a little. First put your own bundler in the global project/plugins.sbt

 addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.6.4") 

Then enter the configuration for the native package in build.sbt in the routine . In the above example, enter masterserver/build.sbt follows:

 // Setup the packager packageArchetype.java_application // Enable JAR export for staging exportJars := true 

The set of necessary JAR files will be placed in the directory of the target subproject, in this example, masterserver/target/universal/stage/lib

The rest of the subproject configuration may remain in the global build.sbt , but I have not found a way to configure my own packer this way.

+7
source

All Articles