简体   繁体   English

如果定义了项目值,为什么不能覆盖SBT子项目中的设置?

[英]Why can't I override settings in SBT subproject if it defines a Project value?

I have a subproject that defines root like this: 我有一个子项目,定义这样的root

lazy val root = (project in file(".")).enablePlugins(PlayScala)

and doesn't define any other settings. 并且未定义任何其他设置。

In my main project I reference it like this: 在我的主项目中,我这样引用它:

lazy val mylib = (project in file("mylib"))
lazy val myapp = (project in file("myapp")).dependsOn(mylib)

The problem is that referenced this way, mylib is built with Scala 2.10 because it doesn't specify a scalaVersion and 2.10 is SBT's default. 问题是这样引用的, mylib是用Scala 2.10构建的,因为它没有指定scalaVersion而2.10是SBT的默认设置。

If I try to override any settings like this: 如果我尝试覆盖任何此类设置:

lazy val mylib = (project in file("mylib")).settings(Seq(scalaVersion := "2.11.8"))

they get ignored. 他们被忽略了。

However, if I remove the lazy val root = ... from subproject's build.sbt the settings passed from the main build file work as expected. 但是,如果我从子项目的build.sbt删除lazy val root = ... ,则从主构建文件传递的设置将按预期工作。 This breaks the subproject's standalone build however since the PlayScala plugin has to be enabled in the main file. 但是,这将中断子项目的独立构建,因为必须在主文件中启用PlayScala插件。

So how can I reference a project like that and override some settings? 那么,如何引用这样的项目并覆盖某些设置呢?

I can work around this by changing the settings globally (ie scalaVersion in ThisBuild ), but I would like to be able to override other things like the project id for instance which is fixed as root in this case. 我可以通过全局更改设置来解决此问题(即scalaVersion in ThisBuild ),但是我希望能够覆盖其他内容,例如项目ID(在这种情况下固定为root

I usually overrides settings like this, and it works fine. 我通常会覆盖这样的设置,并且效果很好。

lazy val mylib = (project in file("mylib")).settings(
  scalaVersion := "2.11.8"
  //any other settings, I want to override, separated by comma
  propertyA := "A",
  propertyB := "C"
)

The difference is, I usually have dependencies in my Play application, but everything is listed under one build.sbt 区别在于,我通常在Play应用程序中具有依赖项,但所有内容都列在一个build.sbt下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM