Why? ¶
As you know I am a rather .NET-orientated developer but with adoption of Kafka you realise lots of tools are written in Java or Scala. This time I needed to get built and deployed Remora - a Kafka lag monitoring tool from Zalando. In the Docker world you’d just use the provided Docker image. However, if you want an old-fashioned deployment you need to build it yourself.
The obvious you do not know ¶
You need to understand a couple of things before building Scala projects.
Linux is your friend ¶
I’ve been running my stuff on Windows Linux Subsystem with Ubuntu.
Scala needs a Java Virtual Machine ¶
You need a JVM installed in order to compile or run Scala projects.
Scala is picky about JVM versions ¶
Make sure your setup meets the requirements of Scala and JVM Compatibility. You can have multiple versions of JDK installed and switch between them using update-java-alternatives
.
The build tool for Scala is SBT ¶
You need to get it installed.
SBT will not include dependencies by default ¶
If you want to have a single self-contained JAR you need to use sbt assembly
.
The basic command looks like ¶
sbt clean assembly
Assuming you’re in the directory where build.sbt
is located. (Usually project’s root).
Modify output file path ¶
sbt 'set assemblyOutputPath in assembly := new File("path/to/my.jar")' clean assembly
Skip tests execution ¶
sbt 'set test in assembly := {}' clean assembly
You can combine the above ¶
sbt 'set assemblyOutputPath in assembly := new File("some.jar")' \
'set test in assembly := {}' clean assembly
And that’s it. Happy building!