SBT publish Scala Artifact to Remote Repository

Publishing and consuming a Scala artifact from a remote repository was something I found to be a little disjointed when I first started learning Scala and how to publish build artifacts. So, I created a little blog to help anyone else(or my future self) on how to use the SBT publishTo feature and SBT resolvers to push and pull build artifacts. This article is making the assumption you already have your artifact built or have read my post on how to build an artifact and that you know the location of where you want to publish this artifact or have read my post on creating a remote repository. Lastly, for more details I would highly recommend taking a look at the SBT documentation for publishing at SBT documentation

To start we will first want to add a few lines of code the build.sbt file that will tell SBT where to publish the artifact.

// Tells SBT how to create the directory and how to add the artifact
publishMavenStyle := true

// Tells SBT where to publish when running publishTo
//publishTo := Some(Resolver.sftp("Generic Repository Name","ftp.yourSitesFTP.com","/directoryInYourFTPSite"))
publishTo := Some(Resolver.sftp("Thinkovator Maven Repo","ftp.thinkovator.com","/maven"))

Next we will want to go to a command line, open up the location of the project and run sbt.
Once in the SBT interpreter we will want to run the command publishTo

publishTo

If you do not have the credentials specified in the SBT script it will prompt you to enter them for the sftp site.

Now that the build artifact is published to the remote location it can be consumed by other application simply by telling SBT that this repository exists and what artifact to grab. To accomplish this, just add a few lines to the build.sbt of the project that needs to use the hosted artifact.

//resolvers += "Generic title for the repo" at "repository URL"
resolvers += "Thinkovator Maven Repo" at "http://maven.thinkovator.com/"

//libraryDependencies += "topDirectoryInRootDirectoryOfMavenRepository" % "artifactName" % "Version"
libraryDependencies += "default" % "com-thinkovator-common" % "1.0.0"

Leave a Reply

Your email address will not be published. Required fields are marked *