Code snippets used in blog post "Defining Multi-project Builds with sbt": https://pbassiner.github.io/blog/defining_multi-project_builds_with_sbt.html
Last active
March 27, 2023 18:06
-
-
Save pbassiner/5ec3209743f42b3f67fbb54b72b446f4 to your computer and use it in GitHub Desktop.
Blog Post - Defining Multi-project Builds with sbt: code snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val commonDependencies = Seq( | |
dependencies.typesafeConfig, | |
dependencies.akka, | |
dependencies.scalatest % "test", | |
dependencies.scalacheck % "test" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "sbt-multi-project-example" | |
organization in ThisBuild := "com.pbassiner" | |
scalaVersion in ThisBuild := "2.12.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val assemblySettings = Seq( | |
assemblyJarName in assembly := name.value + ".jar", | |
assemblyMergeStrategy in assembly := { | |
case PathList("META-INF", xs @ _*) => MergeStrategy.discard | |
case _ => MergeStrategy.first | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) |
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
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?