Working offline with SBT and SNAPSHOT dependencies

前端 未结 4 379
梦如初夏
梦如初夏 2020-12-28 16:28

I have never been able to work offline with SBT on any of my projects. Now I\'m in the middle of a move and my wardrobe-server hosting nexus is offline.

So running s

相关标签:
4条回答
  • 2020-12-28 17:03

    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.

    0 讨论(0)
  • 2020-12-28 17:17

    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)

    0 讨论(0)
  • 2020-12-28 17:25

    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.

    0 讨论(0)
  • 2020-12-28 17:27

    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.

    0 讨论(0)
提交回复
热议问题