为什么 sbt 每次清理后都运行依赖解析? [英] Why sbt runs dependency resolution every time after clean?
问题描述
SBT 每次在 clean
之后都会运行依赖解析,即使项目依赖管理配置没有更改.在 CI 服务器上运行时,这很耗时.
但是文档 说:
<块引用>- 通常情况下,如果自上次成功解析后没有更改依赖管理配置并且检索到的文件仍然存在目前,sbt 不要求 Ivy 执行解析.
每次我使用 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/.."/分辨率缓存"新的 InlineIvyConfiguration(paths, rs, Nil, Nil, off, Option(lock(app)), check, Some(resCacheDir), s.log)}
现在使用 Build.scala
中的此代码,解析缓存被放置在项目根目录中,因此在 clean
之后保留,但无论如何解析正在完成.所以我认为这种方法是错误的或不足的.
因为目录 target/resolution-cache
包含 Ivy 报告.很明显,您在 clean
操作时删除了所有 target
内容.
恕我直言,如果您想保留分辨率状态,您必须在项目中将其指向 target
之外的某个位置.
已更新.
与 SBT.0.12.4.RC1
- 在 IvyConfiguration 中查找
resolution-cache
的使用位置 检查 IvyConfiguration 的位置 - 在项目范围内
<代码>>检查常春藤配置[信息] 任务:sbt.IvyConfiguration[信息] 说明:[信息] 常规依赖管理 (Ivy) 设置,例如解析器和要使用的路径.[信息] 提供者:[信息] {file:/home/ezh/projects/sbt/}xsbt/*:ivy-configuration[信息] 依赖项:[信息] xsbt/*:离线
在 build.sbt 中修复它.
ivyConfiguration <<= (ivyConfiguration, baseDirectory) map {case (c: InlineIvyConfiguration, b) =>进口c._新的 InlineIvyConfiguration(路径、解析器、其他解析器、模块配置、localOnly, 锁, 校验和, resolutionCacheDir.map(_ => b/"123"), log)案例(其他,_)=>其他//未知的东西}
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) =>进口c._新的 InlineIvyConfiguration(路径、解析器、其他解析器、模块配置、localOnly, 锁, 校验和, resolutionCacheDir.map(_ => b/"123"), log)案例(其他,_)=>其他//未知的东西}缓存目录 <<= baseDirectory/"234"
<小时>
与 SBT.0.13.x
@deprecated("使用streams提供的cacheDirectory.", "0.13.0")
https://github.com/sbt/sbt/issues/1208
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:
- 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.
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
- Find where
resolution-cache
is used - in IvyConfiguration 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
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
:)
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
这篇关于为什么 sbt 每次清理后都运行依赖解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!