Tuesday 15 December 2015

Scala project Inter Dependency with other project

Some times,  you might want hierarchy for internal projects or dependency with other projects workspace.

Lets say, you are building a library and  you want to use the classes of that library in your project.
Maven has such facility to include parent project directly.

SBT has similar option as well. We can write small scala snippet which can take care of this.

all you need to do is, create build.scala in <Project_Folder>/project directory.
and write place the below code.

import sbt._
import Keys._

object MyBuild extends Build {
  val parent_project = RootProject(file("/Users/srini/workspace/Project1"))
  val main = Project(id = "srini2", base = file(".")).dependsOn(parent_project)


}

Here, the current project depends on Project1 and works with classes in that folder. So, we created parent_project with the proper path. then, main project calls the dependsOn method with that one. 

This will ensure the dependency hierarchy. 

Note: Please make sure your scala code is in src/main/scala other wise sbt might not be able to recognize.

No comments:

Post a Comment