Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dependsOn to instruct sbt to package dependent projects in multi-project build?

Tags:

sbt

I created a multi-project build in sbt. Here's build.sbt in the main directory:

lazy val root = project in file(".") aggregate(data, reco, result)

lazy val data = project dependsOn(common)

lazy val reco = project 

lazy val result = project dependsOn(common)

lazy val common = project

When I use package or one-jar command, the classes and resources in common project are not packaged into data or result jars. So when I run the generated jar by

java -jar data_2.10-1.0-onejar.jar

it leads to NoClassDefFoundError as a consequence.

So could anyone help me deal with such problem? Thanks in advance.

like image 712
Dzanvu Avatar asked Mar 21 '14 09:03

Dzanvu


People also ask

What is ThisBuild in sbt?

Typically, if a key has no associated value in a more-specific scope, sbt will try to get a value from a more general scope, such as the ThisBuild scope. This feature allows you to set a value once in a more general scope, allowing multiple more-specific scopes to inherit the value.


1 Answers

Your dependent projects are not exporting Jars (producing classes only). Put the following line in the build.sbt of all dependent projects (including your current project too, if necessary):

exportJars := true

That should fix it.

like image 186
Vikash Madhow Avatar answered Sep 19 '22 17:09

Vikash Madhow