简体   繁体   中英

cd command in gradle not working

The cd command in my Gradle task is not working. 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. You are setting the commandLine property 3 times.

  • 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

If you want to run multiple execs in a single task you might want to use project.exec() instead of Exec task. Eg:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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