sbt Library Dependencies et al

  • 3rd party library dependency (commonly resolved using maven or ivy)
  • hard wired jar filepath (less commonly used and is found in situations where the dependency is not managed by a maven like repository).
  • sub-project based dependency using dependsOn

Managed Dependencies

libraryDependencies += organization %% moduleName % version


libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.0"     % "test" % Provided


libraryDependencies += "log4j" % "log4j" % "1.2.15" exclude("javax.jms", "jms")


dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % "3.7.0-M11"

Unmanaged Dependencies

unmanagedBase := baseDirectory.value / "custom_lib"

Docker package

addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.8.2")
docker / dockerfile := {
val jarFile: File = (Compile / packageBin / sbt.Keys.`package`).value
val dependencies = (Compile / dependencyClasspathAsJars).value
val jarTarget = s"/app/${jarFile.getName}"
def addLibPath(files: Seq[File]) ="/app/" + _.getName)
val classpathString = (Seq(jarTarget, "/app/config") ++ addLibPath(dependencies.files)).mkString(":")

val banner =
"""echo "Using JAVA_OPTS: ${JAVA_OPTS}"
|echo "Using args $@"
val javaEnv = "java -Dfile.encoding=UTF-8 $JAVA_OPTS"
val args = """"$@""""

val content =
|echo '${name.value} - v${version.value}'
|echo 'Built on ${} - ${git.gitHeadCommit.value.getOrElse("No head commit")}'
|$javaEnv -cp $classpathString $mainclass $args

val programName = "my-app"

val startScript = file(s"""/tmp/$programName""")
IO.write(startScript, content, append = false)

new sbtdocker.Dockerfile {
add(dependencies.files, "/app/")
add(startScript, s"""/$programName""")
run("chmod", "+x", s"""/$programName""")
add(jarFile, jarTarget)
run("mkdir", "-p", "/app/config")
run("touch", "/app/config/application.conf")
env("JAVA_OPTS", "-Xms8g")
env("JAVA_HOME", "/usr/lib/jvm/jre")
sbt 'project sub-project-1' docker dockerPush

Publishing to Maven

ThisBuild / resolvers += "Artifactory-release" at ""
ThisBuild / resolvers += "Artifactory-snapshot" at ""
ThisBuild / credentials += Credentials(Path.userHome / ".sbt" / "credentials")
sbt 'project sub-project-1' publishLocal publish


resolvers += Resolver.file("local-ivy", file(Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns)




Listener and reader

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Our Agile Project Process — hmm? yet another & my problem

Clarksons’s Farm on Amazon Prime

Dynamic Pluggable Microservice Framework Lite

4.5 C++ Language Quick Start

Logical vs. Syntactical Errors in Code

Deploying Deep-Learning Models to Kubernetes on the IBM Cloud

Flutter App Development- An Introduction

Optimize a Jenkins Pipeline with AWS Codebuild

Accident Lawyer Sandy Utah

accident lawyer sandy utah

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Listener and reader

More from Medium

Testing AMQP Consumer reconnect with testcontainers

ANTLR + Scala: An introduction to Metaprogramming

Currying, the constructor of functions

Technology Adoption at Castlight