2013-06-19 32 views
23

即使項目依賴項管理配置沒有更改,SBT也會在每次clean之後運行依賴項解析。在CI服務器上運行時這很耗時。爲什麼每次清理後sbt都會運行依賴關係解析?

但文檔says

  1. 通常,如果自上次成功的分辨率不依賴管理配置已更改和檢索文件仍然 目前,SBT不問常春藤進行解析。

如何從每次我建項目,sbt clean publish-local時間做依賴解析SBT停下來?

更新

我發現,SBT也運行分辨率時,我在交互模式sbt進入。

UPDATE2

由於@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後保留,但分辨率正在反正做。所以我認爲這種做法是錯誤的或不足的。

回答

9

因爲包含常春藤報告目錄target/resolution-cache的抑制這一點。很明顯,你刪除所有target內容,而clean操作。

恕我直言,如果你想保留分辨率狀態,你必須將它指向你的項目,從target以外的地方。

已更新。

VS 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" 

VS SBT.0.13.x

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

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

+0

我該怎麼做? –

+0

查看我更新的問題 –

+1

用你自己的雙手? SBT非常有表現力。確定爲你特別:)))和我作爲一個有趣的案例。 – Ezhik

6

可能是因爲你有SNAPSHOT依賴關係。他們隨時可能改變,所以必須在每次運行中解決。你可以用

offline := true 
+0

我知道快照。情況並非如此。 Sbt爲所有可用的依賴運行解析。 –

+0

對不起,我應該在哪裏應用這行代碼build.sbt?您能否提供一些背景...... – khebbie

+0

@khebbie在您的sbt命令行(REPL)中運行'set offline:= true'或者用'sbt'運行sbt set offline:= true「run'。你理論上也可以將它添加到你的build.sbt中,但是你總是需要編輯你的構建文件來切換離線模式。 –

4

您可以防止clean從刪除與此設置某些文件:

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

不適用於0.13.1。 – Golly

5

這適用於我在0.13.1。

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

在0.13.1中對我無效。 –

+0

在0.13.2中適用於我,您需要將該行添加到所有子項目中 – sam