Use SBT To Build Pure Java Project

Yes this is entirely possible. Nothing to setup really, a small build.sbt file should do the trick, something like:

organization := "your.group.id"

name := "Your project"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq( <any normal jar deps> )

And run sbt package from the command line.


Sure, you can. Example configuration:

name := "myName"
version := "0.1"
organization := "org.myorganization"

javacOptions in (Compile, compile) ++= Seq("-source", "1.8", "-target", "1.8", "-g:lines")

crossPaths := false // drop off Scala suffix from artifact names.
autoScalaLibrary := false // exclude scala-library from dependencies

Summing up. I love SBT, but I felt necessary to write the full build with all the tricky parts of using it for java. Note that this setup might be better than a maven one because you'll have nice features such as incremental testing or even incremental runs. Also consider adding sbt-assembly plugin if you have dependencies and want to create fat jars (executables).


For me, it also helped a bit to remove the scala version information from the generated artifact paths, as described in this answer. You'll also want to remove the Scala library as a dependency from any pom or ivy file you publish.

Here's what you'll need:

crossPaths := false
autoScalaLibrary := false

Tags:

Java

Build

Sbt