Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference external sbt project from another sbt project?

Tags:

scala

sbt

I have the following setup of a Scala application and a common core library: root

 -> /ApplicationA    -> /project      -> /build.sbt  -> /CoreLibrary    -> /project      -> /build.sbt 

I want to add a reference from ApplicationA to CoreLibrary à la Eclipse project reference, so that every time CoreLibrary changes ApplicationA is built as well. I´ve tried the following contents of build.Scala for ApplicationA:

  val core = Project(       id = "platform-core",       base = file("../CoreLibrary"))    val main = Project(id = "application, base = file(".")).dependsOn(core) 

However, when compiling ApplicationA SBT complains that a dependency can only be a subdirectory!!:

java.lang.AssertionError: assertion failed: Directory C:\git\CoreLibrary is not contained in build root C:\git\ApplicationA 

This seems completely straightforward, what's the correct way of having this project dependency?

like image 426
Diego Avatar asked Jul 25 '12 15:07

Diego


People also ask

How do we specify library dependencies in sbt?

The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.

What is project in file in sbt?

A project is defined by declaring a lazy val of type Project. For example, : lazy val util = (project in file("util")) lazy val core = (project in file("core")) The name of the val is used as the subproject's ID, which is used to refer to the subproject at the sbt shell.

Where are sbt dependencies stored?

All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.


1 Answers

You can do a source dependency on your project like that :

 lazy val core = RootProject(file("../CoreLibrary"))   val main = Project(id = "application", base = file(".")).dependsOn(core)  

I have a working example with a multimodule play build : https://github.com/ahoy-jon/play2MultiModule/blob/master/playapp/project/Build.scala

But I think the proper way (it depends of your context) of doing it is to create a

 -> /project/    -> Build.scala  -> /ApplicationA    -> /project      -> /build.sbt  -> /CoreLibrary    -> /project      -> /build.sbt 

referencing the two projects and the dependencies between them.

like image 128
jwinandy Avatar answered Sep 29 '22 14:09

jwinandy