作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够为我的 sbt.build
中的所有项目定义一个任务。 :
lazy val project1 = project.in(`.` / "project1)
...
lazy val project2 =
...
lazy val upload = taskKey[Unit]("upload a config file from project to server)
upload := {
val file = baseDirectory.value / "config.json"
...
}
sbt upload
时才有效。 ,但我希望能够为每个子项目调用它:
sbt project1/upload
和
sbt project2/upload
.
inputKey
?
最佳答案
For more advanced users, another way of organizing your build is to define one-off auto plugins in
project/*.scala
. By defining triggered plugins, auto plugins can be used as a convenient way to inject custom tasks and commands across all subprojects.
package something
import sbt._
import Keys._
object UploadPlugin extends AutoPlugin {
override def requires = sbt.plugins.JvmPlugin
override def trigger = allRequirements
object autoImport {
val upload = taskKey[Unit]("upload a config file from project to server")
}
import autoImport._
override lazy val projectSettings = Seq(
upload := {
val n = name.value
println(s"uploading $n..")
}
)
}
ThisBuild / organization := "com.example"
ThisBuild / scalaVersion := "2.12.5"
ThisBuild / version := "0.1.0-SNAPSHOT"
lazy val root = (project in file("."))
.aggregate(project1, project2)
.settings(
name := "Hello"
)
lazy val project1 = (project in file("project1"))
lazy val project2 = (project in file("project2"))
build.sbt
不用提
UploadPlugin
,因为它是一个触发插件。从 shell 你可以调用:
sbt:Hello> project1/upload
uploading project1..
[success] Total time: 0 s, completed Jul 20, 2018
sbt:Hello> project2/upload
uploading project2..
[success] Total time: 0 s, completed Jul 20, 2018
关于scala - Sbt:如何为所有项目定义任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51376982/
我是一名优秀的程序员,十分优秀!