Time to read: 2 minutes.
I wanted a simple, flexible and cheap way of publishing proprietary Maven artifacts created by
sbt projects such that they could be securely retrieved by authorized individuals. I liked the idea of versioned artifacts, but did not want to use GitHub or BitBucket to host the artifacts because of the hassle of maintaining ever-larger git repos. Instead, I opted for S3's optional versioning mechanism.
The technique described here relies on the fact that publishing to a local file (using
sbt publish) generates all the necessary artifacts, which merely need to be copied to the right directory on the Artifactory server. The server need not be anything special: a normal web server works fine, as does
webdav. A variety of other protocols are also supported by
s3cmdto manage the AWS S3 buckets that hold the repository. You can obtain
s3cmdfor most OSes. I found I needed to install
$ sudo pip install python-magic
s3cmdknow your s3 keys:Shell
$ s3cmd --configure
- Create the S3 bucket, which must be unique. If you want to repository to be publicly visible, be sure that the bucket name starts with
www.If you already have the S3 bucket then just omit this step.Shell
$ s3cmd mb s3://www.mymavenrepo
- If you want to repository to be publicly visible, you need to enable the S3 bucket web site option:Shell
$ s3cmd ws-create s3://www.mymavenrepo
- Publish your library to a local repository.
testPublishLibis an example of how to set up a project properly.Shell
$ sbt publish
- Copy your locally published artifacts to S3. You can either type it out longhand:Shell
$ s3cmd -P sync ~/.ivy2/local/com/micronautics/test_publish_lib \ s3://www.mymavenrepo/snapshots/com/micronautics/test_publish_lib... (note that the
-Poption makes the files publicly visible), or you can use
$ s3publish com/micronautics/test_publish_lib
- If your repository is not public, you will need to provide authentication in a file which I called ~/.sbt/awsCreds.sbt for convenience:~/.sbt/awsCreds.sbt
credentials += Credentials("AWS Realm", "www.mavenrepo.s3.amazonaws.com", "myUserId", "myPassword")
- Use the published artifact from your sbt project by including a resolver of the form:
"AWS Snapshots" at "https://www.mavenrepo.s3.amazonaws.com/snapshots"The
TestPublishAppproject is a working example of how to do that.
Following is the script I wrote to upload to S3, which I called
s3publish. It assumes you are always publishing a snapshot; and that the files should be public. I leave it to you to extend this script to handle releases and private content if you have the need.