Skip to content

Instantly share code, notes, and snippets.

@pbassiner
Last active March 27, 2023 18:06
Show Gist options
  • Save pbassiner/5ec3209743f42b3f67fbb54b72b446f4 to your computer and use it in GitHub Desktop.
Save pbassiner/5ec3209743f42b3f67fbb54b72b446f4 to your computer and use it in GitHub Desktop.
Blog Post - Defining Multi-project Builds with sbt: code snippets
lazy val commonDependencies = Seq(
dependencies.typesafeConfig,
dependencies.akka,
dependencies.scalatest % "test",
dependencies.scalacheck % "test"
)
lazy val dependencies =
new {
val typesafeConfigV = "1.3.1"
val pureconfigV = "0.8.0"
val monocleV = "1.4.0"
val akkaV = "2.5.6"
val scalatestV = "3.0.4"
val scalacheckV = "1.13.5"
val typesafeConfig = "com.typesafe" % "config" % typesafeConfigV
val akka = "com.typesafe.akka" %% "akka-stream" % akkaV
val monocleCore = "com.github.julien-truffaut" %% "monocle-core" % monocleV
val monocleMacro = "com.github.julien-truffaut" %% "monocle-macro" % monocleV
val pureconfig = "com.github.pureconfig" %% "pureconfig" % pureconfigV
val scalatest = "org.scalatest" %% "scalatest" % scalatestV
val scalacheck = "org.scalacheck" %% "scalacheck" % scalacheckV
}
lazy val global = project
.in(file("."))
.settings(settings)
.aggregate(
common,
multi1,
multi2
)
lazy val common = project
.settings(
settings,
libraryDependencies ++= commonDependencies
)
lazy val multi1 = project
.settings(
settings,
libraryDependencies ++= commonDependencies ++ Seq(
dependencies.monocleCore,
dependencies.monocleMacro
)
)
.dependsOn(
common
)
lazy val multi2 = project
.settings(
settings,
libraryDependencies ++= commonDependencies ++ Seq(
dependencies.pureconfig
)
)
.dependsOn(
common
)
name := "sbt-multi-project-example"
organization in ThisBuild := "com.pbassiner"
scalaVersion in ThisBuild := "2.12.3"
lazy val global = project
.in(file("."))
.aggregate(
common,
multi1,
multi2
)
lazy val common = project
lazy val multi1 = project
.dependsOn(
common
)
lazy val multi2 = project
.dependsOn(
common
)
lazy val assemblySettings = Seq(
assemblyJarName in assembly := name.value + ".jar",
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case _ => MergeStrategy.first
}
)
lazy val multi1 = project
.settings(
settings,
assemblySettings,
libraryDependencies ++= commonDependencies ++ Seq(
dependencies.monocleCore,
dependencies.monocleMacro
)
)
.dependsOn(
common
)
lazy val multi2 = project
.settings(
settings,
assemblySettings,
libraryDependencies ++= commonDependencies ++ Seq(
dependencies.pureconfig
)
)
.dependsOn(
common
)
lazy val settings = Seq(
scalacOptions ++= Seq(
"-unchecked",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-language:postfixOps",
"-deprecation",
"-encoding",
"utf8"
),
resolvers ++= Seq(
"Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)
)
lazy val global = project
.in(file("."))
.settings(settings)
.aggregate(
common,
multi1,
multi2
)
lazy val common = project
.settings(settings)
lazy val multi1 = project
.settings(settings)
.dependsOn(
common
)
lazy val multi2 = project
.settings(settings)
.dependsOn(
common
)
@Naresh523
Copy link

Thanks for the post, but i'm not get common dependencies to shared to sub-projects, should i add build.sbt in the sub-projects too?

@ZviMints
Copy link

Can you also add a Dockerfile example?

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