Skip to main content
 首页 » 编程设计

scala之为什么sbt每次清理后都运行依赖解析

2024年12月31日7jiqing9006

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

但是文档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 clean publish-local 构建项目时,如何阻止 sbt 执行依赖项解析?

更新

我发现当我使用 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 之后保留,但无论如何都在解决。所以我认为这种方法是错误的或不足的。

请您参考如下方法:

因为目录target/resolution-cache包含 Ivy 报告。很明显你删除了所有target内容同时 clean手术。

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

更新。

对比 SBT.0.12.4.RC1

  • 找哪里resolution-cache用于 - 在 IvyConfiguration
  • 检查 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 
    
  • 在 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 的指针:)
  • 修理它。
    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