问题描述
在 sbt shell 中如何设置子项目的设置?
In sbt shell how do I set a setting for a subproject?
我知道我可以project subproject
然后set key := value
,但我不想一直切换项目.理想情况下,与以下内容没有太大区别:
I know I can project subproject
then set key := value
, but I don't want to have to keep switching projects. Ideally something not too different from:
set key in subproject := value
推荐答案
我觉得问题是你在 build.sbt
中定义了你的项目,而它们在 sbt 中似乎不可见安慰.至少在 sbt 的当前版本中 - 请参阅 this issue 和 这个问题实际上在几天前才修复(!)
I think the problem is that you have defined your projects in build.sbt
, and they seem not to be visible in the sbt console. At least in the current version of sbt - see this issue and this issue that were in fact fixed just a couple of days ago (!)
我找到了两种方法来克服这个限制.
I have found two ways to overcome this limitation.
set version in "projectId" := "some-version"
在 project/Build.scala 文件中创建完整的构建定义
使用以下构建定义文件 build/Build.scala
:
import sbt._
import Keys._
object Build extends Build {
lazy val projectA, projectB = project
}
你应该可以在 projectA 中执行 set version :="1.42-SNAPSHOT
并达到预期的效果.
you should be fine to execute set version in projectA := "1.42-SNAPSHOT
with the expected effect.
此外,您可以在 build.sbt
中为每个子模块设置包含项目定义和其余配置的 build/Build.scala
.使用 set
会非常好.
Additionally you could just have the build/Build.scala
containing the project definition and rest of the configuration have in build.sbt
for each submodule. It'd work perfectly fine with set
.
这篇关于如何在 sbt shell 中设置子项目(不使用项目命令)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!