Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use SBT To Build Pure Java Project

Tags:

java

build

sbt

Historically I have used Ant+Ivy or Maven for building my Java projects. I'm now looking at non-xml based solutions.

Gradle can compile, jar and publish my project with few issues.

Can I do the same with SBT? If so, can you provide a simple example of using sbt to build a java only project.

like image 819
opticyclic Avatar asked Nov 28 '11 13:11

opticyclic


People also ask

Can sbt build Java?

sbt has support for compiling Java sources with the limitation that dependency tracking is limited to the dependencies present in compiled class files.

Is sbt a build tool?

sbt is an open-source build tool for Scala and Java projects, similar to Apache's Maven and Ant. Its main features are: Native support for compiling Scala code and integrating with many Scala test frameworks. Continuous compilation, testing, and deployment.

What version of Java does sbt use?

For sbt users, JDK 11 support requires minimum sbt version 1.1. 0. sbt 1.3.


2 Answers

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 
like image 30
raimohanska Avatar answered Sep 22 '22 17:09

raimohanska


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.

like image 135
Hiery Nomus Avatar answered Sep 19 '22 17:09

Hiery Nomus