MetallicPriest
MetallicPriest

Reputation: 30765

How to add repositories which require authentication in sbt project

Getting help from this site, I have put something like that in my build.sbt file to be able to access some private Maven repositories. However, these repositories also require a username and password for authentication. How can I add that here?

resolvers ++= Seq(
   "PrivateRepo1" at "http://privaterepo1/releases/",
   "PrivateRepo2" at "http://privaterepo2/maven/2/"
)

I even tried to add this above, but still couldn't make it work.

credentials += Credentials("PrivateRepo1", 
  "http://privaterepo1/releases/", "<uname>", "<password>")
credentials += Credentials("PrivateRepo2", 
  "http://privaterepo2/maven/2/", "<uname>", "<password>")

Note that these private repositories are hosted on Nexus repository manager.

Upvotes: 1

Views: 532

Answers (1)

dvir
dvir

Reputation: 2566

When you add the credentials, you should specify only the host:

credentials += Credentials(
  "PrivateRepo1", 
  "privaterepo1.com",
  "<uname>",
  "<password>"
)

unrelated, avoid specifying the credentials in the code.
you can read the credentials from environment variables for example

credentials += Credentials(
  "PrivateRepo1", 
  "privaterepo1.com",
  sys.env.getOrElse("private_repo_user", "Unknown"),
  sys.env.getOrElse("private_repo_pass", "Unknown")
)

Upvotes: 1

Related Questions