Working offline with SBT and SNAPSHOT dependencies

青春壹個敷衍的年華 提交于 2019-11-30 03:15:02

This seems like a terrible hack, but you can specify your ivy cache as an ivy repository, so that once your dependencies are downloaded, they can be resolved from the cache.

For example, your ~/.sbt/repositories could look like this:

[repositories]
  local
  maven-central
  cache: file://${user.home}/.ivy2/cache, [organisation]/[module]/ivy-[revision].xml, [organisation]/[module]/[type]s/[module]-[revision].[type]

Note: I had to set the ivy and artifact patterns explicitly. Add the local cache below any other repos so they get tried first.

Me neither can use it in a one-liner.

But if I start sbt and then in sbt I use set offline := true it's working well.

There is a wiki page here: https://github.com/sbt/sbt/wiki/User-Stories:--Offline-mode-and-Dependency-Locking , edited in May, that says that SBT's notion of offline isn't working properly. This may be one reason why your build continues to try to resolve dependencies against remote repositories even when the offline setting is set.

Starting from sbt 0.13.7, you can work offline when you use the dependency cache

To make it short:

  • add updateOptions := updateOptions.value.withCachedResolution(true) in your project settings (and in all subprojects settings)
  • run sbt clean compile once online. It run like before, checking all resolution. But also create and store the resolved dependency graph locally (in ~/.sbt/0.13/dependency).

Then, if you don't change your dependencies, sbt will always use the cached dependency and won't need network (I just tried)

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