将任务添加到 Build.scala [英] Add task to Build.scala

查看:37
本文介绍了将任务添加到 Build.scala的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Tasks.html 解释了如何向 build.sbt 添加任务,但如何向 build.scala 添加任务?谢谢

The document http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Tasks.html explains how to add a task to build.sbt, but how do you add one to build.scala? Thanks

推荐答案

声明 TaskKey 的部分在两种格式中都是相同的:val myTask = taskKey...代码>.

The part where you declare the TaskKey is the same in either format: val myTask = taskKey....

您写出Initialize[Task[T]] 的部分是相同的:myTask := ....

The part where you write out your Initialize[Task[T]] is the same: myTask := ....

唯一的区别是后者出现的上下文.

The only difference is the context in which the latter thing appears.

.sbt格式中,它自己出现,用空行与其他东西分开.

In the .sbt format, it appears by itself, separated from other things by blank lines.

.scala 格式中,您必须将设置添加到项目中.这记录在 http://www.scala-sbt.org/release/docs/Getting-Started/Full-Def.html 并且无论我们谈论的是任务还是常规设置都是一样的.

In the .scala format, you have to add the setting to the project. That's documented at http://www.scala-sbt.org/release/docs/Getting-Started/Full-Def.html and is the same regardless of whether we're talking about a task or a regular setting.

这是一个完整的工作示例:

Here's a complete working example:

import sbt._
object MyBuild extends Build {
  val myTask = taskKey[Unit]("...")
  lazy val root =
    Project(id = "MyProject", base = file("."))
      .settings(
        myTask := { println("hello") }
    )
}

这篇关于将任务添加到 Build.scala的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆