scala - fullRunTask 与 sbt 中的非默认项目
问题描述
我build.sbt
用不同的来源定义了几个项目。我想保持根项目保持原样,使用它自己的源集(和类路径),但添加一个 sbt 任务来编译和运行非默认项目。
这是(缩短的)build.sbt
:
lazy val root = project in file(".")
lazy val anotherModule = project in file("modules/another")
lazy val runAnother = taskKey[Unit]("Run a task from anotherModule")
fullRunTask(initialImport, Compile, "another.module.Main")
another.module
is,事实上, in modules/another/src
and so 不包含在根项目中。
运行时,在类路径中sbt runAnother
找不到another.module
。
我不希望root
项目依赖,anotherModule
因为除此任务外,根项目不需要其中的代码。
如何使用指定模块的类路径运行此任务?
解决方案
runner
可以用来代替fullRunTask
这样
lazy val anotherModule = project in file("modules/another")
lazy val runAnother = taskKey[Unit]("Run task with the classpath of runAnother sub-project")
runAnother := {
(runner in Compile).value.run(
mainClass = "another.module.Main",
classpath = (anotherModule / Compile / fullClasspath).value.files,
options = Array[String](),
log = streams.value.log
)
}
注意我们如何访问anotherModule
子项目的类路径
classpath = (anotherModule / Compile / fullClasspath).value.files
现在sbt runAnother
应该能够anotherModule
在默认项目中运行子项目root
。
推荐阅读
- python - 如何在 Keras 中使用 deconv2d 获得与原始输入大小相同的层?
- javascript - 我可以一次跟踪输入字段的文本更改,而不是每次输入吗?
- socket.io - angular Universal + socket.io,如何正确等待浏览器端?
- javascript - Heroku 托管网站 - 非工作 JavaScript
- windows - Tortoise SVN - 菜单项未显示
- python - 在nestedExpr pyparsing中转义空格
- python - Python 如何在一个 file.txt 中写入 5 行,在新的 file1.txt 中写入另外 3 行,例如 +=1
- mysql - 在 MySql 中存储完全相同的小数点
- javascript - 角度通用 ReferenceError 导航器未定义
- android - 如何强制应用增加媒体声音而不是通话声音