Skip to content

Instantly share code, notes, and snippets.

@davideicardi
Last active October 1, 2019 09:31
Show Gist options
  • Save davideicardi/006f9d8970bc19432b4d4e996f8e7537 to your computer and use it in GitHub Desktop.
Save davideicardi/006f9d8970bc19432b4d4e996f8e7537 to your computer and use it in GitHub Desktop.
Scala/sbt minimal multi projects setup

Scala/sbt minimal multi projects setup

Assume that you have the following directory structure:

  • your-app
    • project1
      • src
        • main
          • scala
            • App.scala
          • resources (optional)
        • test
    • project2
      • src
        • main
          • scala
            • App.scala
          • resources (optional)
        • test
    • project
      • assembly.sbt (optional)
      • build.properties
    • build.sbt

build.sbt

lazy val commonSettings = Seq(
  organization := "your-app",
  version := "0.1",
  scalaVersion := "2.11.8"
)

// Libs for unit testing common
val scalacticDep = "org.scalactic" %% "scalactic" % "3.0.5" % "test"
val scalatestDep = "org.scalatest" %% "scalatest" % "3.0.5" % "test"

// val anotherDep = "bla.bla" %% "bla-bla" % "1.0.0"

// variables "project1" and "project2" are used as folders

lazy val project1 = project
  .settings(
    commonSettings,
    libraryDependencies += scalacticDep,
    libraryDependencies += scalatestDep,
    // libraryDependencies += anotherDep
  )

lazy val project2 = project
  .settings(
    commonSettings,
    libraryDependencies += scalacticDep,
    libraryDependencies += scalatestDep,
    // libraryDependencies += anotherDep
  )
  // .dependsOn(project1) // add this if a project depends on another projects

lazy val root = (project in file("."))
  .aggregate(project1, project2)
  .settings(
    commonSettings
  )

build.properties

sbt.version=1.2.8

Usage

To execute a command like run/test/.. on a project run:

sbt project1/run

To run all tests:

sbt test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment