简体   繁体   English

为什么sbt每次清理后运行依赖解析?

[英]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. 即使项目依赖关系管理配置未更改,SBT也会在每次clean后运行依赖项解析。 This is time consuming when running on CI server. 在CI服务器上运行时,这非常耗时。

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. 通常,如果自上次成功解析后没有依赖关系管理配置发生更改且检索到的文件仍然存在,则sbt不会要求Ivy执行解析。

How can I stop sbt from doing dependency resolution every time I build project with sbt clean publish-local ? 每次使用sbt clean publish-local构建项目时,如何阻止sbt进行依赖项解析?

Update 更新

I've discovered that sbt also runs resolution when I enter in interactive mode with sbt . 我发现当我与sbt进入交互模式时,sbt也会运行解析。

Update2 UPDATE2

As @Ezhik pointed if I can preserve target/resolution-cache then sbt will not resolve dependencies after clean. 正如@Ezhik指出的那样,如果我可以保留target/resolution-cache那么sbt将不会在清理后解析依赖关系。 So I tried to move resolution-cache out from target dir: 所以我试图从目标目录移出resolution-cache

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. 现在使用Build.scala代码解析缓存放在项目根目录中,因此在clean后保留,但无论如何Build.scala解析。 So I assume this approach is wrong or insufficient. 所以我认为这种方法是错误的或不充分的。

Because of directory target/resolution-cache that contains Ivy reports. 由于目录target/resolution-cache包含Ivy报告。 It is obviously that you remove all target content while clean operation. 显然,您在clean操作时删除所有target内容。

IMHO You must point it in your project to somewhere out from target if you want to preserve resolution state. 恕我直言如果你想保留分辨率状态,你必须将它指向你的项目中的某个target

Updated. 更新。

vs SBT.0.12.4.RC1 vs SBT.0.12.4.RC1

  1. Find where resolution-cache is used - in IvyConfiguration 在IvyConfiguration中查找使用resolution-cache位置
  2. Inspect where IvyConfiguration located - in project scope 检查IvyConfiguration的位置 - 在项目范围内

     > 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. 修复它在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. 4测试... Ups ...分辨率仍然有效......调查。 -> - >

target/scala-2.10/cache/default-920e5d/global/update/output cache contain pointers to resolution-cache :) target/scala-2.10/cache/default-920e5d/global/update/output cache包含指向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 vs SBT.0.13.x

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

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

Might be that you have SNAPSHOT dependencies. 可能是你有SNAPSHOT依赖。 They are subject to change anytime so must be resolved on every run. 它们随时都有变化,因此必须在每次运行时解决。 You can suppress this with 你可以用这个来抑制它

    offline := true

这适用于0.13.1。

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

You can prevent clean from deleting certain files with this setting: 您可以防止clean的删除与此设置某些文件:

// path should be adapted for newer sbt versions
cleanKeepFiles <+= cacheDirectory / "update"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM