Gradle — execute multiple commands from task

前端 未结 4 2051
-上瘾入骨i
-上瘾入骨i 2020-12-30 21:14

I have 2 separate apps (in one project) that require 2 separate builds (sencha cmd). I have been asked to create a gradle script that will do the builds for both apps.

相关标签:
4条回答
  • 2020-12-30 21:29

    It's impossible to configure (run) multiple commands for the task of type Exec. commandLine it's just a setter - the last one wins. If you need to run multiple commands the best idea is to implement multiple tasks as @RaGe suggested in the comment or to write a custom task and use groovy's native mechanisms - execute method.

    0 讨论(0)
  • 2020-12-30 21:29

    You also can use gradle methods instead create fictive tasks

    task senchaBuild() {
     doLast {
        senchaBuild_steps()
     }
    }
    
    void senchaBuild_steps() {
     exec {
        workingDir 'src/main/app/MYAPP'
        commandLine 'cmd', 'c', 'sencha app build'
     }
     exec {
        workingDir 'src/main/app/MYOTHERAPP'
        commandLine 'cmd', 'c', 'sencha app build'
     }
    }
    
    0 讨论(0)
  • 2020-12-30 21:42

    You can use the second way to declare task types on gradle.

    task senchaCmdBuild {
      doLast {
        exec {
          workingDir 'src/main/app/MYAPP'
          commandLine 'cmd', 'c', 'sencha app build'
        }
        exec {
          workingDir 'src/main/app/MYOTHERAPP'
          commandLine 'cmd', 'c', 'sencha app build'
        }
      }
    }
    

    You need put the exec method in doLast in order to be executed only on execution flow

    0 讨论(0)
  • 2020-12-30 21:47

    Use .execute() at doLast block

    task myTask(group: "my-group") {
           doLast {
                 println "Starting..."
                 println "echo \"MyEcho1\"".execute().text.trim()
                 println "echo \"MyEcho2\"".execute().text.trim()
           }
        }
    
    0 讨论(0)
提交回复
热议问题