Gradle,commandLine'cmd','/ c','echo doLast!'什么也没做 [英] Gradle, commandLine 'cmd', '/c', 'echo doLast!' does nothing

查看:334
本文介绍了Gradle,commandLine'cmd','/ c','echo doLast!'什么也没做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关 Gradle Exec

a>并创建以下 build.gradle

 任务startTomcat类型:Exec){
commandLine'cmd','/ c','echo init startTomcat'
}

任务stopTomcat(类型:Exec){

//在windows上:
commandLine'cmd','/ c','echo init stopTomcat!'
doLast {
commandLine'cmd','/ c','echo当我运行 gradlew stopTomcat ,输出如下所示:

 孵化功能。 
:stopTomcat
init stopTomcat!

我没有看到 doLast stopTomcat!为什么我不能在 doLast ?中执行命令?

解决方案

你的任务是Exec类型。 commandLine 方法调用通过传递 cmd / c echo init stopTomcat!。这发生在配置阶段。



然后任务在执行阶段运行并打印:

  init stopTomcat! 

然后 doLast 块启动并配置任务,传递 cmd / c echo doLast stopTomcat!到它。这个配置在taks已经运行时没有效果。



要获得第二个打印输出,您可以执行:

< pre $ 任务stopTomcat(类型:Exec){

//在窗口上:
commandLine'cmd','/ c','echo init stopTomcat !'
doLast {
exec {
commandLine'cmd','/ c','echo doLast stopTomcat!'
}
}
}

这是如何调用exec任务的另一种方式。


I'm reading about Gradle Exec and created the following build.gradle:

task startTomcat(type:Exec) {
    commandLine 'cmd', '/c', 'echo init startTomcat'
} 

task stopTomcat(type:Exec) {

    // on windows:
    commandLine 'cmd', '/c', 'echo init stopTomcat!'
    doLast {
        commandLine 'cmd', '/c', 'echo doLast stopTomcat!'
    }
}

When I run gradlew stopTomcat, the output looks like this:

Parallel execution with configuration on demand is an incubating feature.
:stopTomcat
init stopTomcat!

I don't see the line doLast stopTomcat! Why can't I execute a command in doLast?

解决方案

Your task is of type Exec. The commandLine method call configures the task by passing the cmd, /c and echo init stopTomcat! to it. This happens in the config phase.

Then the task runs in execution phase and prints:

init stopTomcat!

Then the doLast blocks starts and configures the task, passing cmd, /c and echo doLast stopTomcat! to it. This configuration has no effect as the taks already ran.

To get the second print out, you could do:

task stopTomcat(type:Exec) {

    // on windows:
    commandLine 'cmd', '/c', 'echo init stopTomcat!'
    doLast {
        exec {
            commandLine 'cmd', '/c', 'echo doLast stopTomcat!'
        }
    }
}

This is another way how to invoke the exec task.

这篇关于Gradle,commandLine'cmd','/ c','echo doLast!'什么也没做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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