How to add dependencies in build.sbt so that they are available in modules?

Asked

Viewed 51 times

2

I am starting to use SBT for scala projects and would like to create a project like:

APP
...Module1
...Module2
    ...Module3

...
build.sbt

would like to know how to build.sbt dependencies so that they are also used in modules.

Thank you for your attention

1 answer

0

You can define the modules independently in build.sbt as follows:

lazy val module1 = project
  .settings(
    libraryDependencies ++= deps
  )

lazy val module2 = project
  .settings(
    libraryDependencies ++= deps
  )

lazy val module3 = (project in file("modules/module3"))
  .settings(
    libraryDependencies ++= deps
  )

 val deps = List(
    "dependencia1" %% "exemplo" % "X.Y.Z",
    "dependencia2" %% "exemplo" % "X.Y.Z",
  )

In the example above modules are defined including the list of dependencies. modulo3 explicitly defines the path from which sbt searches its main App.

Another way is to define a dependency relationship between modules:


lazy val module2 = project
  .settings(
    libraryDependencies ++= deps
  )

lazy val module3 = (project in file("modules/module3"))
  .settings()
  .dependsOn(module2)

In this case it is not necessary to reset the value libraryDependencies pro module3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.