Gradle-从任务执行多个命令 [英] Gradle -- execute multiple commands from task

查看:94
本文介绍了Gradle-从任务执行多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个单独的应用程序(在一个项目中),需要2个单独的版本(sencha cmd).我被要求创建一个gradle脚本来为两个应用程序进行构建.

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.

我创建了一个构建一个应用程序的任务,但是在使用同一任务构建第二个应用程序时遇到了麻烦.

I created a task that builds one app, but am having troubles using the same task to build the 2nd app.

这是我到目前为止所拥有的:

This is what I have so far:

task senchaCmdBuild (type: Exec) {
  workingDir 'src/main/app/MYAPP'
  commandLine 'cmd', 'c', 'sencha app build'
}

这很好用.

当我将以下两行添加到上述任务中时:

When I add the following 2 lines to above task:

 workingDir 'src/main/app/MYOTHERAPP'
 commandLine 'cmd', 'c', 'sencha app build'

第一个命令被忽略,只有第​​二个命令执行.

the first command is ignored and only the second command executes.

那么我是否可以同时执行一个任务的两个命令?

So is there anyway I can execute both commands with one task?

推荐答案

您可以使用第二种方法在gradle上声明任务类型.

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'
    }
  }
}

您需要将exec方法放在doLast中,以便仅在执行流程上执行

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

这篇关于Gradle-从任务执行多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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