25

clean即使项目依赖管理配置没有更改,SBT 每次都会运行依赖解析。在 CI 服务器上运行时,这很耗时。

但文件

  1. 通常,如果自上次成功解析后没有更改依赖管理配置并且检索到的文件仍然存在,则 sbt 不会要求 Ivy 执行解析。

每次我用 构建项目时,如何阻止 sbt 进行依赖解析sbt clean publish-local

更新

我发现当我进入交互模式时 sbt 也会运行分辨率sbt

更新2

正如所@Ezhik指出的,如果我可以保留target/resolution-cache,那么 sbt 将不会在清理后解决依赖关系。所以我试图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)
      }

现在,Build.scala解析缓存中的此代码被放置在项目根目录中,因此在 之后保留clean,但无论如何解析正在完成。所以我认为这种方法是错误的或不足的。

4

4 回答 4

9

因为target/resolution-cache包含常春藤报告的目录。很明显,您target在操作时删除了所有内容clean

target恕我直言,如果您想保留分辨率状态,您必须在项目中将其指向某个地方。

更新。

与 SBT.0.12.4.RC1

  1. 查找resolution-cache使用位置 - 在 IvyConfiguration
  2. 检查 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. 在 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 测试... Ups... 分辨率仍然有效... 调查。->

target/scala-2.10/cache/default-920e5d/global/update/output缓存包含指向resolution-cache:)的指针

  1. 修理它。

    cacheDirectory <<= baseDirectory / "234"
    

测试。知道了。跳过分辨率。

所需配置的摘要更改:

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"

与 SBT.0.13.x

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

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

于 2013-06-20T07:23:39.597 回答
6

可能是您有 SNAPSHOT 依赖项。它们随时可能发生变化,因此必须在每次运行时解决。你可以用

    offline := true
于 2013-06-19T12:36:50.627 回答
6

这适用于我 0.13.1。

cleanKeepFiles ++= Seq("resolution-cache", "streams").map(target.value / _)
于 2014-03-14T12:40:13.003 回答
5

您可以clean使用此设置防止删除某些文件:

// path should be adapted for newer sbt versions
cleanKeepFiles <+= cacheDirectory / "update"
于 2014-01-15T09:25:59.843 回答