Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build multiple jar files using scala sbt

Tags:

scala

sbt

In my project I have the following structure:

src/

plugins/

\__ mpc

|__ oper

I compile all of the scala files in src into a single jar (the main program), then each subdirectory in plugins contains scala files that should build a plugin jar to be loaded by the main program (so one jar for plugins/mpc and another for plugins/oper).

In the root I have a build.sbt:

name := "mrtoms"

organization := "chilon"

version := "0.1"

libraryDependencies ++= Seq("commons-httpclient" % "commons-httpclient" % "3.1")

crossPaths := false

scalaHome := Some(file("/usr/share/scala"))

target := file("project/target")

scalaSource in Compile <<= baseDirectory(_ / "src")

mainClass := Some("org.chilon.mrtoms.MrToms")

That builds my main jar file from the files in src just fine.. how do I add jars for the sources file in each plugin directory?

like image 238
crelbor Avatar asked Jun 15 '11 21:06

crelbor


1 Answers

Seems that you need full configuration (at the moment you are using basic one):

https://github.com/harrah/xsbt/wiki/Full-Configuration

In your case, root project is your main jar. Each plugin should then have it's own project, that root project aggregates. Full configuration can be something like this:

import sbt._

object MyBuild extends Build {
    lazy val root = Project("root", file(".")) aggregate (mpc, oper) 
    lazy val mpc  = Project("mpc", file("plugins/mpc")) dependsOn(pluginApi)
    lazy val oper = Project("sub2", file("plugins/oper")) dependsOn(pluginApi)
    lazy val pluginApi = Project("pluginApi", file("plugins/api"))
}
like image 163
tenshi Avatar answered Sep 29 '22 11:09

tenshi