0

I have a root project that depends on a subproject1. And subproject1 depends on subproject2. Does that imply that I Can use subproject2's source code directly in root?

lazy val root =
  Project(id = "root", base = file(".")).dependsOn(sub1)

lazy val sub1 =
  Project(id = "sub1").dependsOn(sub2)

lazy val sub2 =
  Project(id = "sub2")
Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
Helix112
  • 305
  • 3
  • 12

2 Answers2

3

Yes.

This can easily be checked.

build.sbt

name := "sbtdemo"

version := "0.1"

ThisBuild / scalaVersion := "2.13.4"

lazy val root =
  Project(id = "root", base = file(".")).dependsOn(sub1)

lazy val sub1 =
  Project(id = "sub1", base = file("sub1")).dependsOn(sub2)

lazy val sub2 =
  Project(id = "sub2", base = file("sub2"))

sub2/src/main/scala/App.scala

object App {
  def foo() = println("foo")
}

src/main/scala/Main.scala

object Main {
  def main(args: Array[String]): Unit = {
    App.foo() // foo
  }
}
Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
2

Yes. From Classpath dependencies by sbt:

lazy val core = project.dependsOn(util)

Now code in core can use classes from util. This also creates an ordering between the projects when compiling them; util must be updated and compiled before core can be compiled.

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35