Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
737 views
in Technique[技术] by (71.8m points)

scala - Why sbt runs dependency resolution every time after clean?

SBT runs dependency resolution every time after clean even if project dependency management configuration hasn't changed. This is time consuming when running on CI server.

But documentation says:

  1. Normally, if no dependency management configuration has changed since the last successful resolution and the retrieved files are still present, sbt does not ask Ivy to perform resolution.

How can I stop sbt from doing dependency resolution every time I build project with sbt clean publish-local ?

Update

I've discovered that sbt also runs resolution when I enter in interactive mode with sbt.

Update2

As @Ezhik pointed if I can preserve target/resolution-cache then sbt will not resolve dependencies after clean. So I tried to move resolution-cache out from target dir:

ivyConfiguration <<= (externalResolvers, ivyPaths, offline, checksums, appConfiguration, target, streams) map { (rs, paths, off, check, app, t, s) =>
        val resCacheDir = t / ".." / "resolution-cache"
        new InlineIvyConfiguration(paths, rs, Nil, Nil, off, Option(lock(app)), check, Some(resCacheDir), s.log)
      }

Now with this code in Build.scala resolution cache is placed in project root and is therefore preserved after clean, but resolution is being done anyway. So I assume this approach is wrong or insufficient.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...