简体   繁体   English

gradle中的cd命令无法正常工作

[英]cd command in gradle not working

The cd command in my Gradle task is not working. 我的Gradle任务中的cd命令不起作用。 Using it to go to another folder. 用它来转到另一个文件夹。

task assembleTask(overwrite: true, type:Exec) {
    commandLine "gradle", "assembleDev"

    doLast {
        commandLine "cd tests"
        commandLine "ls"
    }
}

The Exec task only runs once. Exec任务只运行一次。 You are setting the commandLine property 3 times. 您正在设置commandLine属性3次。

  • once in the configuration phase, before the task runs 一旦处于配置阶段,在任务运行之前
  • twice after the task has run (this will have no effect) 任务运行后两次(这将没有任何效果)

If you want one task to run another, you might do 如果您希望一个任务运行另一个任务,您可能会这样做

task assembleTask {
   dependsOn assembleDev
   doLast {
       file('tests').listFiles().each { File f ->
          println f.name
       }
   }
}

Or perhaps you want a GradleBuild task, not sure 或许你想要一个GradleBuild任务,不确定

If you want to run multiple execs in a single task you might want to use project.exec() instead of Exec task. 如果要在单个任务中运行多个执行程序,可能需要使用project.exec()而不是Exec任务。 Eg: 例如:

task assembleTask {
    doLast {
        exec {
            commandLine 'foo'            
        }
        exec {
            commandLine 'bar'
        }
        exec {
            commandLine 'baz'
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM