2014-06-12 52 views
1

我正在編寫一個任務,將幾個但不是全部的子項目打包在一起,並使用排除設置和task.all(scope filter)來選擇項目。然而,sbt總是說References undefined settings at runtime如何選擇子項目在運行時打包(使用ScopeFilter)?

這裏是項目/ build.scala我用跟隨有錯誤,我需要你的建議:

import sbt._ 
import Keys._ 

object build extends Build { 
    lazy val root = Project(
    id = "root", 
    base = file("."), 
    aggregate = Seq(a,b), 
    settings = Seq(
     exclude := Seq(a), 
     module := moduleImpl.value, 
     modules := modulesImpl.value 
    ) 
) 

    lazy val a = Project(
    id = "a", 
    base = file("a") 
) 

    lazy val b = Project(
    id = "b", 
    base = file("b") 
) 

    val exclude = settingKey[Seq[ProjectReference]]("excludes") 
    val module = taskKey[String]("module") 
    val modules = taskKey[Seq[String]]("modules") 

    def moduleImpl = Def.task { 
     projectID.value.organization 
    } 

    def modulesImpl = Def.taskDyn { 
    module.all(ScopeFilter(inAggregates(ThisProject) -- inProjects(exclude.value: _*))) 
    } 
} 

這是我真的想擺脫的錯誤:

> show modules 
[trace] Stack trace suppressed: run last root/*:modules for the full output. 
[error] (root/*:modules) sbt.Init$RuntimeUndefined: References to undefined settings at runtime. 
[error] Total time: 0 s, completed 2014-06-12 16:48:05 

任何想法解決這個問題?

回答

1

sbt抱怨,因爲您使用的任務沒有在子項目中定義。

解決辦法是不要把它在module,但moduleImpl

lazy val moduleImpl = Def.task { 
    projectID.value.organization 
} 

def modulesImpl = Def.taskDyn { 
    moduleImpl.all(ScopeFilter(inAggregates(ThisProject) -- inProjects(exclude.value: _*))) 
} 

PS。當你做

Project(
    id = "root", 
    base = file("."), 
    aggregate = Seq(a,b), 
    settings = Seq(
    exclude := Seq(a), 
    module := moduleImpl.value, 
    modules := modulesImpl.value 
) 
) 

你覆蓋所有的默認設置。您可能需要在Project上添加Defaults.defaultSettings或使用settings方法。

相關問題