如何覆蓋多構建SBT項目中的子項目設置/任務?例如,這裏有兩個非常簡單的SBT項目:SBT:覆蓋多構建dependsOn /聚合項目中的設置
〜/項目/後端/ build.sbt
name := "backend"
// old version of scala
scalaVersion := "2.9.1"
〜/ mycode的/ docker_builder/build.sbt
lazy val backend = RootProject(file("~/projects/backend"))
lazy val root = (project in file(".")).
settings(
// Doesn't work because sub-project already defines name
name in backend := "sub-overriden",
// Doesn't override {backend/}backend/*:scalaVersion since backend already defines scalaVersion in Global config
scalaVersion in backend := "2.10.1",
// Does define new setting in sub-project: {backend/}backend/test:scalaVersion (because backend did not define scalaVersion in test config)
scalaVersion in (backend, Test) := "2.10.2"
).
aggregate(sub1)
// dependsOn(sub1)
在上面的示例中,我試圖覆蓋名稱和scalaVersion,但正如在comme nts,根項目無法覆蓋在後端項目中顯式定義的任何設置/任務。現在,我假設這是預期的行爲,因爲RootProject和它的父ProjectReference指向一個完全不同的SBT的身材,但如果是這樣的話,爲什麼我們允許引進新設置到構建,如:scalaVersion in(後端,測試)?
任何解決方法或其他解決方案?
上面的示例後端項目過於簡單化 - 我們團隊中的實際後端項目基於多個項目格式,大約有一兩個子項目和sbt插件 - 但是,幸運的是,我能夠重現上面列表中的問題。
相關:
How to define build-scoped settings in multi-project .sbt builds?
Setting javac options for SBT dependencies
Use common settings in SBT `RootProject`