[英]SBT multi-project build without using lazy vals
I'm working with a huge project with lots of subprojects, some of them with subprojects of their own. 我正在处理一个包含许多子项目的大型项目,其中一些具有自己的子项目。 On top of that, I'd like some of them to be dynamic - given a
List
somewhere in the project build, I'd like to create one project for each of the elements. 最重要的是,我希望其中一些是动态的-给定项目构建中某个位置的
List
,我想为每个元素创建一个项目。
For those reasons, having to define a lazy val
for each project in build.sbt
is very cumbersome. 出于这些原因,必须为
build.sbt
每个项目定义一个lazy val
值非常麻烦。 Is there other way to declare projects, like a addProject
-like method we could call anywhere? 还有其他方法来声明项目,例如可以在任何地方调用的类似
addProject
的方法吗? Is there some SBT plugin that helps with that? 有一些SBT插件可以帮助您吗?
Sbt uses macros to turns top level val
s into projects, so I don't think you will be able to escape that part. Sbt使用宏将顶级
val
转换为项目,因此我认为您将无法转义该部分。 However, you can define all you build in Project => Project
functions: (note that you also composability "for free" with function composition) 但是,您可以定义在
Project => Project
函数中构建的所有对象:(请注意,您还可以使用功能组合“免费”组合)
def myConf: Project => Project =
_.enablePlugins(ScalaJSPlugin)
.settings(scalaVersion := "2.12.0")
Then simply use project.configure(myConf)
for single line project definitions: 然后只需将
project.configure(myConf)
用于单行项目定义:
lazy val subProject1 = project.configure(myConf)
lazy val subProject2 = project.configure(myConf)
lazy val subProject3 = project.configure(myConf)
lazy val subProject4 = project.configure(myConf)
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.