(SBT) How to disable default resolver and only use the company internal resolver?

不问归期 提交于 2019-12-03 06:05:05

问题


We want to use company internal ivy/maven repository (artifactory) to improve the speed of resolving, and downloading the jar files, and also we want to use it to exchange binary jar files between different teams in our organization.

I know we can force SBT to go through proxy by setting ~/.repositories with

[repositories]
  local
  my-ivy-proxy-releases: http://repo.alpinenow.com/artifactory/repo/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  my-maven-proxy-releases: http://repo.alpinenow.com/artifactory/repo/

and then launch SBT with -Dsbt.override.build.repos=true. This method works for me.

However, it's kind of cumbersome to ask all the developers to setup this way. We're wondering if we can override the default resolvers completely in Build.scala, and plugin.sbt without extra configuration.

So far, I've tried the following ways without success.

1) In both Build.scala and plugin.sbt, I added

resolvers := "Local Repo" at "http://repo.alpinenow.com/artifactory/repo/",

externalResolvers := Seq(Resolver.url("Local Repo", url("http://repo.alpinenow.com/artifactory/repo"))(Resolver.ivyStylePatterns)),

but it still downloads the jars from typesafe and maven1.

2) I then decided to put repositories file into project folder, and tried to add java option directly inside plugin.sbt, and Build.scala with

System.setProperty("-Dsbt.override.build.repos", "true"),

System.setProperty("-Dsbt.repository.config", "project/repositories"),

but it still doesn't work. I'm curious when the SBT gets the java options for resolvers since obviously, it's before plugin.sbt and Build.scala.

Any idea?

Thanks.

DB Tsai


回答1:


If you depart from the sbt-extras shell script as a replacement for the default launcher script, I guess you could easily modify that with setting up ~/.repositories and adding -Dsbt.override.build.repos=true. Then all you need to do is ensure your developers use that script.




回答2:


Project level

According to the documentation we should be using externalResolvers:
https://www.scala-sbt.org/release/docs/Library-Dependencies.html#Overriding+default+resolvers

externalResolvers := Seq(
  "Local Repo" at "http://repo.alpinenow.com/artifactory/repo/",
  // some more internal Nexus repositories
)

Plugin level

You'll have to do it also in your project folder for plugins like in project/resolvers.sbt.

Global SBT level

And if you also want SBT it self to resolve from a specific repo, you'll need to do as described here: https://www.scala-sbt.org/1.x/docs/Proxy-Repositories.html




回答3:


I am always adding SBT build as part of my repo in SVN/GIT, close with code. Then I have no such problems.

It costs about 1MB space so is quite cheap and solves a lot of problems. All developers use identical build tool. Even if I try to create Continues Integration or more advanced Continues Delivery process all SBT configs will be already well configured in my SCM. I will get one source of true :)



来源:https://stackoverflow.com/questions/19584393/sbt-how-to-disable-default-resolver-and-only-use-the-company-internal-resolver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!