18.15. Publishing Your Library
Problem
You’ve created a Scala project or library with SBT that you want to share with other users, creating all the files you need for an Ivy repository.
Solution
Define your repository information, then publish your project with
sbt publish
or sbt publish-local
.
For my SoundFilePlayer library, I added this setting to my build.sbt file to define the location of my local repository:
publishTo := Some(Resolver.file("file", new File("/Users/al/tmp")))
I then ran sbt publish
, and SBT
generated the following files:
$ sbt publish
[info] Wrote
/Users/al/SoundFilePlayer/target/scala-2.10.0/sounds_2.10.0-1.0.pom
[info] :: delivering :: default#sounds_2.10.0;1.0 :: 1.0 :: release ::
[info] delivering ivy file to
/Users/al/SoundFilePlayer/target/scala-2.10.0/ivy-1.0.xml
[info] published sounds_2.10.0 to
/Users/al/tmp/default/sounds_2.10.0/1.0/sounds_2.10.0-1.0.pom
[info] published sounds_2.10.0 to
/Users/al/tmp/default/sounds_2.10.0/1.0/sounds_2.10.0-1.0.jar
[info] published sounds_2.10.0 to
/Users/al/tmp/default/sounds_2.10.0/1.0/sounds_2.10.0-1.0-sources.jar
[info] published sounds_2.10.0 to
/Users/al/tmp/default/sounds_2.10.0/1.0/sounds_2.10.0-1.0-javadoc.jar
[success] Total time: 1s
Without doing anything to define a “local Ivy repository,” I get
the following results when running the publish-local
task:
$ sbt publish-local
[info] Wrote /Users/al/SoundFilePlayer/target/scala-2.10.0/sounds_2.10.0-1.0.pom [info] :: delivering :: default#sounds_2.10.0;1.0 :: 1.0 :: ...
Get Scala Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.