18.10. Using GitHub Projects as Project Dependencies
Problem
You want to use a Scala library project on GitHub as an SBT project dependency.
Solution
Reference the GitHub project you want to include in your project/Build.scala file as a RootProject.
For example, assuming you want to use the Scala project at https://github.com/alvinj/SoundFilePlayer as a dependency, put the following contents in a file named project/Build.scala in your SBT project:
importsbt._objectMyBuildextendsBuild{lazyvalroot=Project("root",file("."))dependsOn(soundPlayerProject)lazyvalsoundPlayerProject=RootProject(uri("git://github.com/alvinj/SoundFilePlayer.git"))}
You can now use that library in your code, as shown in this little test program:
packagegithubtestimportcom.alvinalexander.sound._importjavazoom.jlgui.basicplayer._importscala.collection.JavaConversions._importjava.util.MapobjectTestJavaSoundextendsApp{valtestClip="/Users/al/Sarah/Sounds/HAL-mission-too-important.wav"valplayer=SoundFilePlayer.getSoundFilePlayer(testClip)player.play}
With this configuration and a basic build.sbt file, you can run this code as
usual with the sbt run
command.
Including this GitHub project is interesting, because it has a number of JAR files in its own lib folder, and compiling and running this example works fine.
Note that although this works well for compiling and running your
project, you can’t package all of this code into a JAR file by just
using the sbt package command. Unfortunately, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access