SBT:多构建依赖/聚合项目中的覆盖设置 [英] SBT: Override setting in multi-build dependsOn/aggregate project

查看:17
本文介绍了SBT:多构建依赖/聚合项目中的覆盖设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How do I override a sub-project setting/task in a multi-build SBT project? For example, here are two very simple SBT projects:

~/projects/backend/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)

In the sample above, I'm trying to override both name and scalaVersion, but as noted in the comments, the root project is not able to override any setting/task explicitly defined explicitly in the backend project. Now I'm assuming this is expected behavior, since RootProject and it's parent ProjectReference point to a completely different SBT build, but if this is the case, why are we allowed to introduce new settings into the build, e.g: scalaVersion in (backend, Test)?

Any workarounds or other solutions?

The sample backend project above is a gross oversimplification--our actual backend project in our team is based on the multi-project format with about a dozen or two sub-projects and sbt-plugins--however, fortunately I'm able to reproduce the issue with the listing above.

Related:
How to define build-scoped settings in multi-project .sbt builds?
Setting javac options for SBT dependencies
Use common settings in SBT `RootProject`

解决方案

There doesn't seem to be any way to override settings from the subproject directly from the main build. When you create the Project its settings doesn't even contain the definitions from the subproject's build.sbt yet.

What you can do though is call .addSbtFiles(file("overrides.sbt")) (paths are resolved relative to the subproject's base dir) and then put the overrides into this separate file which is loaded after the subproject's build.sbt.

这篇关于SBT:多构建依赖/聚合项目中的覆盖设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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