[英]SBT: execute task using other task value
I redefine my tests to supply some arguments from configuration to test suite: 我重新定义了测试,以提供从配置到测试套件的一些参数:
This is an excerpt from my Build.scala: 这是我的Build.scala的摘录:
object Build extends Build {
lazy val myProject = (project in file("my_project")).settings(
test in Test := myProjectTest.value
)
val myProjectTest = Def.task {
(testOnly in Test).toTask(" tests.Suites -- " +
s"-Ddbserver=localhost " +
s"-Ddbport=3306 ").value
}
}
This works ok. 这样可以。
Now, I wanted to give my test suite the name of an artifact like this: 现在,我想给我的测试套件一个这样的工件名称:
val myProjectTest = Def.task {
val art = (Keys.artifactPath in (Compile, packageBin)).value
(testOnly in Test).toTask(" tests.Suites -- " +
s"-Dartifact=${art.getCanonicalPath} " +
s"-Ddbserver=localhost " +
s"-Ddbport=3306").value
}
But it shows the following error message: 但它显示以下错误消息:
[error] /tmp/aa/project/Build.scala:17: Illegal dynamic reference: art
[error] s"-Dartifact=${art.getCanonicalPath} " +
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
I know something about SBT internals, macros, task dependency graph, and I even managed to solve some of my tasks using scopes. 我对SBT内部,宏,任务依赖图有所了解,甚至设法使用范围解决了一些任务。 Here I tried to use map or flatMap on (Keys.artifactPath in (Compile, packageBin))
but cannot achieve the desirted result. 在这里,我尝试(Keys.artifactPath in (Compile, packageBin))
上使用map或flatMap (Keys.artifactPath in (Compile, packageBin))
但无法实现所需的结果。 Whenever I try to access .value
I get Illegal dynamic reference
. 每当我尝试访问.value
,都会得到Illegal dynamic reference
。
Please, guide me. 请指导我。 I just need to pass the value of task to other task (inputKey) parameters. 我只需要将task的值传递给其他task(inputKey)参数。
SBT version: 0.13.5 SBT版本: 0.13.5
By trial and error I've done what I wanted eventually using Def.taskDyn
(dynamic task): 通过反复试验,我最终使用Def.taskDyn
(动态任务)完成了我想做的事情:
object Build extends Build {
lazy val myProject = (project in file("my_project")).settings(
test in Test := myProjectTest.value
)
lazy val myProjectTest = Def.taskDyn {
val art = (Keys.artifactPath in (Compile, packageBin)).value
(testOnly in Test).toTask(" tests.Suites -- " +
s"-Dartifact=${art.getCanonicalPath} " +
s"-Ddbserver=localhost " +
s"-Ddbport=3306")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.