gpt4 book ai didi

scala - sbt 0.11 需要运行任务示例

转载 作者:行者123 更新时间:2023-12-04 08:45:44 25 4
gpt4 key购买 nike

我的项目仍在使用 sbt 0.7.7,我发现拥有可以从 sbt 提示符运行的实用程序类非常方便。我还可以将其与单独维护的属性结合起来 - 通常用于从主机到主机更改的环境相关值。这是我在 project/build 下的项目定义示例目录:

class MyProject(info: ProjectInfo) extends DefaultProject(info) {
//...
lazy val extraProps = new BasicEnvironment {
// use the project's Logger for any properties-related logging
def log = MyProject.this.log
def envBackingPath = path("paths.properties")
// define some properties that will go in paths.properties
lazy val inputFile = property[String]
}

lazy val myTask = task { args =>
runTask(Some("foo.bar.MyTask"),
runClasspath, extraProps.inputFile.value :: args.toList).dependsOn(compile)
describedAs "my-task [options]"
}
}

然后我可以将我的任务用作 my-task option1 option2在 sbt shell 下。

我在 https://github.com/harrah/xsbt/wiki 阅读了新的 sbt 0.11 文档。包括 Tasks 上的部分和 TaskInputs坦率地说,我仍在为如何完成我在 0.7.7 上所做的事情而苦苦挣扎。

似乎额外的属性可以简单地替换为单独的 environment.sbt ,必须在 project/build.scala 中定义任务在设置之前 build.sbt .看起来也有补全支持,看起来很有趣。

除此之外,我有点不知所措。我如何完成我对新 sbt 所做的事情?

最佳答案

您可以定义这样的任务:

val myTask = InputKey[Unit]("my-task")

而你的设置:
val inputFile = SettingKey[String]("input-file", "input file description")

您还可以定义一个新的配置,如:
lazy val ExtraProps = config("extra-props") extend(Compile)

将此配置添加到您的项目并使用它来设置此配置的设置:
lazy val root = Project("root", file(".")).config( ExtraProps ).settings(
inputFile in ExtraProps := ...
...
myTask in ExtraPops <<= inputTask { (argTask:TaskKey[Seq[String]]) =>
(argTask, inputFile) map { (args:Seq[String], iFile[String]) =>
...
}
}
).dependsOn(compile)

然后使用 extra-props:my-task 启动您的任务

关于scala - sbt 0.11 需要运行任务示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8098183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com