Gradle - 如何在新的cmd窗口中执行bat文件?

时间:2015-08-12 12:28:15

标签: gradle build.gradle

build.gradle的一部分:

task runCraftBukkit(type:Exec) {
    println "Starting CraftBukkit server..."
    commandLine = ['cmd', '/C', 'start', 'D:/Projects/WorkSpaces/WorldCleaner/devserver/start.bat'] // cmd /C start D:/Projects/WorkSpaces/WorldCleaner/devserver/start.bat
    workingDir = file('./devserver/')
}
jar.doLast {
    runCraftBukkit.execute()
}

输出:

15:13:54: Executing external task 'jar'...
Starting CraftBukkit server...
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE

BUILD SUCCESSFUL
...

但是命令提示符窗口和不会出现

问题: 我做错了什么?

1 个答案:

答案 0 :(得分:3)

工作解决方案:

task runCraftBukkit(type:Exec) {
    doFirst {
        println "Starting CraftBukkit server..."
        workingDir = file('./devserver/')
        commandLine = ['cmd', '/C', 'start', 'start.bat']
        // cmd /C start D:/Projects/WorkSpaces/WorldCleaner/devserver/start.bat
    }
}
jar.finalizedBy runCraftBukkit

我花了很多时间寻找错误。问题不在于:)

主要问题是任务没有执行。决策证明方法.finalizedBy

现在:

...
:jar UP-TO-DATE
:runCraftBukkit
Starting CraftBukkit server...
...

这正是我想看到的:]