You can put credentials in a file and reference in credentials.sbt
so that sbt
will load it, and use it while publishing or dependency download,
STEP1: setup creds file path in ~/.sbt/1.0/plugins/credentials.sbt
echo 'credentials += Credentials(Path.userHome / ".sbt" / ".credentials")' > ~/.sbt/1.0/plugins/credentials.sbt
note: echo some-stuff > some-file
will redirect contents to a file. echo
is a linux command
STEP2: Your ~/.sbt/.credentials
would look like,
realm=Artifactory Realm // or Sonatype Nexus Repository Manager
host=server.com // don't put in http:// or https:// protocal
user=your.username.for.server.com
password=password.for.server.com
STEP3: setup publish config in build.sbt
something like below:
publishTo in ThisBuild := {
if (isSnapshot.value)
Some("Artifactory Realm" at "server.com" + "/artifactory/libs-snapshot-local")
else
Some("Artifactory Realm" at "server.com" + "/artifactory/libs-release-local")
}
STEP4: you can verify credentials.sbt
is picked up by sbt, just by running sbt clean compile
$ sbt clean compile
[info] Loading settings for project global-plugins from idea.sbt,credentials.sbt ...
Related resources:
Official documentation: https://www.scala-sbt.org/1.0/docs/Publishing.html
How to access a secured Nexus with sbt?
SBT publish to JFrog artifactory