jiluo
jiluo

Reputation: 2346

Override sbt default resolvers with authenticated repo?

I have a maven repository with authentication, and I want sbt to use only the maven repository

My build.sbt:

resolvers += "My Repo" at "https://my.repository.addresss/repo/"

externalResolvers <<= resolvers map { rs =>
    Resolver.withDefaultResolvers(rs, mavenCentral = false)
}

But when I type sbt clean compile, it is still download from repo1.maven.org, I can not override it!

As my maven repo has to authenticate, so it always fails when I put default repo config in ~/.sbt/repositories

Is there any way that I can use my repo only, and authenticate successful?

Upvotes: 15

Views: 7665

Answers (3)

Mo Tao
Mo Tao

Reputation: 1295

I've met similar situation of yours. The solution is

  1. create ~/.ivy2/.credentials with

    realm=Sonatype Nexus Repository Manager
    host=yourRepo.com
    user=yourUser
    password=yourpassword
    
  2. add this line to build.sbt

    credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
    
  3. create ~/.sbt/repositories according to http://www.scala-sbt.org/1.0/docs/Proxy-Repositories.html

Upvotes: 0

Raven
Raven

Reputation: 11

Try this:

lazy val yourRepo = "yourRepo" at "https://yourRepo.com/nexus/content/groups/public"

fullResolvers := {
    val oldResolvers = fullResolvers.value
    val idx = oldResolvers.map(_.isInstanceOf[DefaultMavenRepository$]).indexOf(true)
    oldResolvers.take(idx) ++ Seq(yourRepo) ++ oldResolvers.drop(idx)
}

Upvotes: 1

Christian
Christian

Reputation: 4593

Unfortunately, I can only help you with one part of your question.

If you only want to use your maven repo, have a look at the sbt documentation, chapter proxy repositories. There the file ~/.sbt/repositories is used. Alternatively, you can also use sbt.boot.properties (see Launcher configuration).

Don't forget to override the build repos from the build scripts as documented here. If you don't do that, sbt still tries to connect to repo1.maven.org.

I did the same thing today (using sbt 0.12.3), and it works!

Upvotes: 6

Related Questions