There is a difference between standalone and using a project as a dependency or another project. In the first case, you should use a plugin, for example sbt-assembly . It will create a single jar file containing the project class files, as well as all its dependencies. If you write an application, then you get a bi-directional jar that you can execute from anywhere.
If you want to use your project A as a dependency for another project B, you have different options. You can simply pack A class files using sbt package (@Channing Walton answer). You can then delete the resulting .jar file in the lib directory of project B. However, if A also requires a library, you must make sure that they also end up in the libraries of project B.
The best approach is to publish your project. You can only do this on your local machine using sbt publish-local . This will store the jar created by package in a special local directory that can be accessed from sbt in another project, along with a POM file that contains A. dependencies. It will use the group identifier (group) and artifact -ID (name) and version of your project A. For example, in build.sbt :
name := "projecta" version := "0.1.0-SNAPSHOT" organization := "com.github.myname" scalaVersion := "2.10.3" publishMavenStyle := true
After publishing with sbt publish-local you can add the following B dependency to your project:
libraryDependencies += "com.github.myname" %% "projecta" % "0.1.0-SNAPSHOT"
If you have a pure Java project, you can omit the suffix of the Scala version, i.e. in Project A:
crossPaths := false autoScalaLibrary := false
And then in Project B:
libraryDependencies += "com.github.myname" % "projecta" % "0.1.0-SNAPSHOT"
(using only one % character between group id and artifact).
Read more about publishing in sbt documentation .
Jan 0, 05 '14 at 20:57 2014-01-05 20:57
source share