Why sbt runs dependency resolution every time after clean?

痴心易碎 提交于 2019-11-28 17:54:08

Because of directory target/resolution-cache that contains Ivy reports. It is obviously that you remove all target content while clean operation.

IMHO You must point it in your project to somewhere out from target if you want to preserve resolution state.

Updated.

vs SBT.0.12.4.RC1

  1. Find where resolution-cache is used - in IvyConfiguration
  2. Inspect where IvyConfiguration located - in project scope

    > inspect ivy-configuration
    [info] Task: sbt.IvyConfiguration
    [info] Description:
    [info]  General dependency management (Ivy) settings, such as the resolvers and paths to use.
    [info] Provided by:
    [info]  {file:/home/ezh/projects/sbt/}xsbt/*:ivy-configuration
    [info] Dependencies:
    [info]  xsbt/*:offline
    
  3. Fix it in build.sbt.

    ivyConfiguration <<= (ivyConfiguration, baseDirectory) map {
      case (c: InlineIvyConfiguration, b) => import c._
        new InlineIvyConfiguration(paths, resolvers, otherResolvers, moduleConfigurations,
         localOnly, lock, checksums, resolutionCacheDir.map(_ => b / "123"), log)
      case (other, _) => other // something unknown
    }
    

4 Test... Ups... resolution is still active... Investigate. ->

target/scala-2.10/cache/default-920e5d/global/update/output cache contain pointers to resolution-cache :)

  1. Fix it.

    cacheDirectory <<= baseDirectory / "234"
    

Test. Got it. Resolution is skipped.

Summary changes for required configuration:

ivyConfiguration <<= (ivyConfiguration, baseDirectory) map {
  case (c: InlineIvyConfiguration, b) => import c._
    new InlineIvyConfiguration(paths, resolvers, otherResolvers, moduleConfigurations,
     localOnly, lock, checksums, resolutionCacheDir.map(_ => b / "123"), log)
  case (other, _) => other // something unknown
}
cacheDirectory <<= baseDirectory / "234"

vs SBT.0.13.x

@deprecated("Use the cacheDirectory provided by streams.", "0.13.0")

https://github.com/sbt/sbt/issues/1208

Might be that you have SNAPSHOT dependencies. They are subject to change anytime so must be resolved on every run. You can suppress this with

    offline := true

This works for me on 0.13.1.

cleanKeepFiles ++= Seq("resolution-cache", "streams").map(target.value / _)

You can prevent clean from deleting certain files with this setting:

// path should be adapted for newer sbt versions
cleanKeepFiles <+= cacheDirectory / "update"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!