SBT在编译后应用任务 [英] SBT apply Task after Compile

查看:196
本文介绍了SBT在编译后应用任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在编译之前自动执行一个任务:

I am able to automatically execute a task before compilation with:

compile in Compile <<= (compile in Compile).dependsOn(myTask)

如何做同样的,但 > compile?

How do I do the same but after compile?

我知道我可以做:

compile in Compile <<= (compile in Compile) map{x=>
  // post-compile work
  doFoo()
  x
}

来执行任意的Scala代码,但是我需要在编译事件发生时自动执行目标任务本身

to execute arbitrary Scala code, but I need to automatically execute the target task itself when a compile event occurs

做类似的操作:

val foo = TaskKey[Unit]("foo", "...")
val fooTask = foo <<= scalaInstance map {si =>
...
} dependsOn(compile in Compile)

从sbt> prompt键入foo即任务在编译后执行,但目标是钩入编译任务本身,所以任何时候编译发生,foo任务在编译完成后自动调用。

works if I type "foo" from sbt> prompt; i.e. task is executed after compile, but the goal is to hook into compile task itself, so anytime a compilation occurs, the foo task is automatically called after compilation completes.

这可能,或者我是以错误的方式挂钩到内置的编译任务?

Is this possible, or am I going about things in the wrong way to hook into the built-in compile task?

推荐答案

,有一些任务取决于你的任务。

In general, there is some task that depends on your task.

如果 compile 用于表示编译和设置然后创建一个 prepareGrunt 任务,该任务取决于 compile myTask 并运行它。

If compile is being used to mean "compile and set things up for Grunt", then create a prepareGrunt task that depends on compile and myTask and run that instead.

如果 myTask 应该在项目的类和资源由其他东西使用,然后使其成为 exportedProducts 的依赖项。 run test 等任务和相关项目中的任务将从该任务获取导出的类路径条目。

If myTask should run before the project's classes and resources are used by something else, then make it a dependency of exportedProducts. Tasks like run and test and tasks in dependent projects will get the exported classpath entries from that task.

在编译后运行一段时间中的危险是, myTask 不会在实际需要它的任务之前运行。在初始化[Task [T]] 上有 triggeredBy 方法,但它很容易被滥用,当已知任务的输出仅在所有任务执行后使用。

The danger in "run sometime after compile" is that myTask won't be run before the task that actually needs it. There is the triggeredBy method on Initialize[Task[T]], but it is easily abused and should only be used when the output of the task is known to be used only after all tasks execute.

这篇关于SBT在编译后应用任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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