Skip to content

sbt Repositories

sbt reads and publishes through a CloudRepo Maven repository. There is no separate sbt repository type. sbt needs three things: the repository URL, a credential whose realm matches CloudRepo’s, and publishTo if you publish.

  • A Maven repository to read from and publish to. Creating a Repository explains how to make one.
  • A repository token that covers it. Choose Download and publish packages when you publish. Repository Tokens shows how to create one. In sbt’s terms, user is the email address that owns the token and password is the token.
  • The repository address, https://your-org.mycloudrepo.io/repositories/your-repo. Its Connection Settings page displays the same address with your organization and repository already filled in.
  • sbt 1.x. The output quoted on this page comes from sbt 1.13.0.

Used on this page only, never saved. Never enter a token or password here.

1. Put the credential in ~/.sbt/.credentials. The file is Java properties. realm and host are both your repository host, and user and password are your email address and the token. Keep the file readable by you alone (chmod 600 ~/.sbt/.credentials).

~/.sbt/.credentials
realm=your-org.mycloudrepo.io
host=your-org.mycloudrepo.io
user=you@example.com
password=YOUR_REPOSITORY_TOKEN

2. Name the repository in build.sbt. resolvers is where sbt reads dependencies from, credentials loads the file you wrote, and publishTo is where sbt publish writes:

build.sbt
resolvers += "CloudRepo" at "https://your-org.mycloudrepo.io/repositories/your-repo"
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
publishTo := Some("CloudRepo" at "https://your-org.mycloudrepo.io/repositories/your-repo")

3. Publish. Run this in the directory of your build.sbt:

Terminal
sbt publish

Expected: [success], and the artifact is listed in the repository in the admin portal. sbt publishes the pom and the jar, and the sources and javadoc jars. A project that depends on the published coordinate resolves it from the same resolvers line, so there is nothing more to run for that.

Keep the token in the platform’s secret store, expose it to the build step as the environment variable CLOUDREPO_TOKEN (and your email as CLOUDREPO_USERNAME), and read both in build.sbt instead of a file. Nothing goes on a command line:

build.sbt
credentials += Credentials(
"your-org.mycloudrepo.io",
"your-org.mycloudrepo.io",
sys.env("CLOUDREPO_USERNAME"),
sys.env("CLOUDREPO_TOKEN")
)

For how each CI system holds a secret, see CI/CD.

Your sbt builds can be faster. sbt downloads through Coursier, and by default Coursier sends the token only after CloudRepo has asked for it twice, so every file takes three requests. Add these lines to build.sbt and sbt sends the token with the first request: one request per file.

build.sbt
val cloudrepoAuth = for {
user <- sys.env.get("CLOUDREPO_USERNAME")
token <- sys.env.get("CLOUDREPO_TOKEN")
} yield "CloudRepo" -> lmcoursier.definitions.Authentication(user, token)
csrConfiguration ~= (c => cloudrepoAuth.fold(c)(a => c.withAuthenticationByRepositoryId(Vector(a))))
updateClassifiers / csrConfiguration ~= (c => cloudrepoAuth.fold(c)(a => c.withAuthenticationByRepositoryId(Vector(a))))
  • These lines are safe to commit. On a machine where CLOUDREPO_USERNAME and CLOUDREPO_TOKEN are not both set, they do nothing, and sbt keeps using ~/.sbt/.credentials.
  • "CloudRepo" is the name in your resolvers line. If you named it something else, use that name.
  • Your email and the token come from CLOUDREPO_USERNAME and CLOUDREPO_TOKEN, set as shown in the In CI section.
  • The last line does the same for sbt updateClassifiers, which downloads sources and javadoc. sbt sets that task up on its own, so the csrConfiguration line above it does not reach it.
  • Keep the credentials line. sbt publish reads it.

A Maven repository guards its releases unless you turn Overwrite Protection off. A second publish of a release version answers 409 Conflict, and the copy already stored stays untouched. Versions ending in -SNAPSHOT are exempt and can be published as often as you like. The rules match Maven’s, described in Maven Overwrite Protection.

Nothing is broken. Raise the version, or switch to a -SNAPSHOT version while you are still iterating.

unauthorized: https://your-org.mycloudrepo.io/... (your-org.mycloudrepo.io) while resolving. sbt asked CloudRepo for the file and sent no credential. The text in parentheses is the realm CloudRepo asked for: put exactly that in realm (and in host) in ~/.sbt/.credentials. If the realm already matches, check that credentials += ... is in the build.sbt of the project that is failing.

Unable to find credentials for [your-org.mycloudrepo.io @ your-org.mycloudrepo.io] while publishing. Same problem on the publish side. sbt lists the realms it has for that host under Is one of these realms misspelled for host, then sends the upload with no credential. Set realm to the value in the first brackets.

403 Forbidden after sbt sends the credential. The credential is good but may not do this. The token does not reach this repository (scope_mismatch_repo), or it has Download packages access and you are publishing. See scope_mismatch_repo and Troubleshooting.

401 Unauthorized that a matching realm does not fix. Either user is not the email address that owns the token, or the token has expired or been revoked. Run the checks in Troubleshooting.

View as Markdown