为什么sbt每次清理后都要运行依赖项解析? [英] Why sbt runs dependency resolution every time after clean?

查看:75
本文介绍了为什么sbt每次清理后都要运行依赖项解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SBT也会在clean之后每次运行依赖项解析.在CI服务器上运行时,这很耗时.

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.

但是文档:

  1. 通常,如果自上次成功解决以来,依赖性管理配置没有更改,并且检索到的文件仍然 目前,sbt不会要求常春藤执行解决方案.
  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进行依赖关系解析?

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

更新

我发现当我与sbt进入交互模式时,sbt也可以运行解析.

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

Update2

正如@Ezhik所指出的,如果我可以保留target/resolution-cache,则sbt在清理后将无法解析依赖项. 因此,我尝试将resolution-cache从目标目录中移出:

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)
      }

现在,此代码在Build.scala分辨率缓存中位于项目根目录中,因此保留在clean之后,但是无论如何都在进行解析.因此,我认为这种方法是错误的或不足的.

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.

推荐答案

由于包含常春藤报告的目录target/resolution-cache.显然,您在clean操作期间删除了所有target内容.

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

恕我直言,如果要保留分辨率状态,必须将其指向项目中的target某处.

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

已更新.

vs SBT.0.12.4.RC1

vs SBT.0.12.4.RC1

  1. 查找在IvyConfiguration中使用resolution-cache的位置
  2. 检查IvyConfiguration的位置-在项目范围内

  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

  • 在build.sbt中修复它.

  • 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测试... ups ...分辨率仍处于活动状态...正在调查. ->

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

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

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

    1. 修复它.

    1. Fix it.

    cacheDirectory <<= baseDirectory / "234"
    

    测试.知道了.分辨率被跳过.

    Test. Got it. Resolution is skipped.

    所需配置的摘要更改:

    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

    这篇关于为什么sbt每次清理后都要运行依赖项解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆