SBT 如何运行 InputTask [英] SBT how to run InputTask

查看:59
本文介绍了SBT 如何运行 InputTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的 SBT 项目中创建一些自定义任务,需要为此调用其他任务.

I am creating some custom tasks in my SBT project and need to call other tasks for that.

如何从我的任务内部调用 inputTasks 并支持它们一些输入?

How can i call inputTasks from inside my tasks and support them some input?

推荐答案

由于您可以围绕此考虑自己的任务,因此我假设您正在尝试使用 run 任务.这需要一些挖掘,但我终于让它工作了;简而言之,这就是您要做的(假设您的任务名为 deployTask,请根据您的需要进行调整):

Since you can factor your own tasks around this I'm assuming you're trying to use the run task. It took a bit of digging, but I've finally made it work; in a nutshell, this is what you do (assuming your task is named deployTask, tweak to match your needs):

deployTask <<= ( fullClasspath in Compile, runner ) map { ( classpath, runner ) =>
        val logger = ConsoleLogger()    // Not sure this is optimal
        Run.executeTrapExit( {
            Run.run( "com.sample.MainClass", 
                     classpath map { _.data }, 
                     Seq( "option1", "option2", "..." ),  // <-- Options go here
                     logger )( runner )
        }, logger )
    }

这不会直接调用 InputTask(我还没有找到一种方法来做到这一点),但它至少可以让您运行任意 Java 代码.

This doesn't invoke the InputTask directly (I haven't found a way to do that yet), but it at least lets you run arbitrary Java code.

这篇关于SBT 如何运行 InputTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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