bbstilson / sbt-codeartifact   0.2.6

MIT License GitHub

An sbt plugin for publishing packages to AWS CodeArtifact.

Scala versions: 2.12
sbt plugins: 1.x

SBT CodeArtifact

Maven

An sbt plugin for publishing/consuming packages to/from AWS CodeArtifact.

Install

First, you will need a CodeArtifact repository. Then, add the following to your sbt project/plugins.sbt file:

addSbtPlugin("io.github.bbstilson" % "sbt-codeartifact" % version)

Usage

Note that when specifying sbt-codeartifact settings in project/*.scala files (as opposed to in the root build.sbt), you will need to add the following import:

import codeartifact.CodeArtifactKeys._

Publishing

CodeArtifact provides instructions on how to connect to your repository. Click "View Connection Instructions", then choose "gradle", then copy the url.

Here's an example build.sbt file that assumes a CodeArtifact repository named "private" in the "com.example" domain has been created:

organization := "com.example"

name := "library"

version := "0.1.0"

scalaVersion := "2.13.4"

codeArtifactUrl := "https://com-example-1234567890.d.codeartifact.us-west-2.amazonaws.com/maven/private"

Then, to publish, run:

sbt:library> codeArtifactPublish

Consuming

A resolver for your repository is added based on the codeArtifactUrl key. You can add more repositories manually like so:

val codeArtifactUrlBase = "https://com-example-1234567890.d.codeartifact.us-west-2.amazonaws.com/maven/"

codeArtifactUrl := codeArtifactUrlBase + "release"
codeArtifactResolvers := List("foo", "bar", "baz").map(repo => codeArtifactUrlBase + repo)

In sbt:

sbt:library> show resolvers
[info] * com-example/release: https://com-example-1234567890.d.codeartifact.us-west-2.amazonaws.com/maven/release
[info] * com-example/foo: https://com-example-1234567890.d.codeartifact.us-west-2.amazonaws.com/maven/foo
[info] * com-example/bar: https://com-example-1234567890.d.codeartifact.us-west-2.amazonaws.com/maven/bar
[info] * com-example/baz: https://com-example-1234567890.d.codeartifact.us-west-2.amazonaws.com/maven/baz

Credentials

Your CodeArtifact Authentication Token is fetched dynamically using the AWS Java SDK. Credentials are resolved using the DefaultCredentialsProvider.

If you would like to provide the token statically (for example, if your AWS creds are unavailable), then you can provide the token as an environment variable:

export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain domain-name --domain-owner domain-owner-id --query authorizationToken --output text --profile profile-name`

SBT Release

If you would like to use this in conjunction with sbt-release, you will need to override the default release process; specifically, the publish step:

import ReleaseTransformations._

releaseProcess := Seq[ReleaseStep](
  checkSnapshotDependencies,
  inquireVersions,
  runClean,
  runTest,
  setReleaseVersion,
  commitReleaseVersion,
  tagRelease,
  // This is the only step that varies.
  releaseStepCommandAndRemaining("codeArtifactPublish"),
  setNextVersion,
  commitNextVersion,
  pushChanges
)