本文介绍了将 sbt 设置作为 fullRunTask 中的参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取设置的值(例如,name)并将其作为参数传递给 fullRunTask?我不明白 fullRunTask 的实现.

How can I get the value of a setting (say, name) and pass it as an argument to fullRunTask? I do not understand the implementation of fullRunTask.

例如:

lazy val foo = TaskKey[Unit]("foo")

fullRunTask(foo, Compile, "foo.Foo", name.value)

不起作用,因为我无法在此上下文中引用 name.value.

does not work because I can't reference name.value in this context.

推荐答案

好的,我从 Josh Suereth 那里得到了一些帮助.使用 fullRunTask 执行此操作有点复杂,但它所做的额外工作(在 myTask 中添加 runner)并不是真正必要的.内联 runTask 的主体做了我需要的.

Ok I got some help from Josh Suereth. Doing this with fullRunTask is a little more complex but the extra stuff it does (adding runner in myTask) does wasn't really necessary. Inlining the body of runTask did what I needed.

lazy val myTask = taskKey[Unit]("my custom run task")

myTask := {
  val r = (runner in Compile).value
  val input = name.value // or any other string setting(s)
  val cp = (fullClasspath in Compile).value
  toError(r.run("my.MainClass", data(cp), Seq(input), streams.value.log))
}

这篇关于将 sbt 设置作为 fullRunTask 中的参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 20:12