“<<=”在 sbt 设置中做什么?
What does "<<=" do in sbt settings?
我正在学习编写一些更高级的 sbt 构建文件,我遇到了 sbt-proguard 的代码:
binaryDeps <<= compile in Compile map { _.relations.allBinaryDeps.toSeq },
inputs <<= fullClasspath in Runtime map { _.files },
libraries <<= (binaryDeps, inputs) map { (deps, in) => deps filterNot in.toSet },
outputs <<= artifactPath map { Seq(_) },
- 我想知道 <<= 在这种情况下是什么意思?
- 如何理解第3行的map函数?
<<=
是 DefinableSetting (mixed in by TaskKey, InputKey, and SettingKey) which provides a way to initialise a build setting. It's described in the older docs here 上的方法:
:= assigns a value, overwriting any existing value. <<= uses existing values to initialize a setting.
本质上,在 0.12(和当前版本,为了兼容性)中,这是一种根据其他构建设置定义构建设置的方法。
正如@sjrd 指出的那样,在 0.13 中引入了 new task setting syntax 允许您使用 :=
代替。
第三行中的 map
通过仅从 binaryDeps
中获取 inputs
中尚未存在的依赖项来创建新的设置值,即 transform 这两个设置到这个新的。
我正在学习编写一些更高级的 sbt 构建文件,我遇到了 sbt-proguard 的代码:
binaryDeps <<= compile in Compile map { _.relations.allBinaryDeps.toSeq },
inputs <<= fullClasspath in Runtime map { _.files },
libraries <<= (binaryDeps, inputs) map { (deps, in) => deps filterNot in.toSet },
outputs <<= artifactPath map { Seq(_) },
- 我想知道 <<= 在这种情况下是什么意思?
- 如何理解第3行的map函数?
<<=
是 DefinableSetting (mixed in by TaskKey, InputKey, and SettingKey) which provides a way to initialise a build setting. It's described in the older docs here 上的方法:
:= assigns a value, overwriting any existing value. <<= uses existing values to initialize a setting.
本质上,在 0.12(和当前版本,为了兼容性)中,这是一种根据其他构建设置定义构建设置的方法。
正如@sjrd 指出的那样,在 0.13 中引入了 new task setting syntax 允许您使用 :=
代替。
第三行中的 map
通过仅从 binaryDeps
中获取 inputs
中尚未存在的依赖项来创建新的设置值,即 transform 这两个设置到这个新的。