Using the Gradle Command-Line(2)

在上一篇中我们学习使用了如何在命令行下去执行多个Task任务,其中希望大家牢记一句话"Each task is executed only once, so **gradle test test **is exactly the same as gradle test".
  接下来我们就跟随gradle官方的教程来开始学习。

Using the Gradle Command-Line(2)_第1张图片
Paste_Image.png

  4.2 Excluding task ,gradle为我们提供了一个命令,去执行包含某一task,的task 。其命令为“**gradle dist -x test
**” 其实就是只需要加上-x参数。举个例子还是昨天的代码:

task compile<<{
     println 'compile source'
}

task compileTest (dependsOn:compile) <<{
      
     println ' compile unit tests'

}

task test(dependsOn:[compile,compileTest])<<{

     println 'running unit tests'


}

task dist(dependsOn:[compile,test])<<{

     println 'building the distribution'

}

我们在命令行中输入如下命令:“gradle dist -x test”,结果如下图:

Using the Gradle Command-Line(2)_第2张图片
Paste_Image.png

相信通过这个例子大家也就明白了。
  4.3 Continuing the build when a failure occurs,这一部分主要说明gradle支持在某些任务失败的时候去继续构建应用,当然gradle默认情况下,只要有任务失败,就会自动停止构建。如果我们需要使用gradle的这一功能,则需要加入一些参数。“ you can use the --continue
option
” 你可以这样去触发这个功能。
  有两点大家需要注意:1 如果您使用了这一个功能,那么gradle在遇到某一个任务失败的时候,它会继续执行构建,知道整个项目构建完毕,在这之中如果遇到,错误,那么gradle将会自动跳过,并在结尾的时候指出其错误。2 即使你使用了gradle的这一功能,如果一个任务报错,那么之后的任务如果它依赖了这一任务,那么它也不会执行,这是gradle处于安全的考虑。我觉得也是很有必要的。
  4.4 Task name abbreviation,这一部分主要是gradle为了简化我们在命令行中的操作而提供的,简而言之,我们在命令行中执行任务的时候,不必去提供task的全称,及简单的拼写就可以执行(以我个人之见,虽然gradle这样提供了,但还是不要这样为好)。所以说上面的代码也可以这样运行。

Using the Gradle Command-Line(2)_第3张图片
Paste_Image.png

  4.5 Selecting which build to execute,这一部分主要gradle给我们提供了在当前目录下,去执行子目录的方法。

Paste_Image.png

Alternatively, you can use the -p option to specify the project directory to use. For multi-project builds you should use -p option instead of -boption.

4.6. Forcing tasks to execute
  许多任务,特别是Gradle本身提供的任务,支持[增量构建] 这样的任务可以基于他们的输入或输出自从他们上次运行以来是否改变来确定他们是否需要运行。 当Gradle显示文本UP-TO-DATE时,您可以轻松识别参与增量构建的任务在构建运行期间在其名称旁边。你可能有时想要强迫Gradle运行所有的任务,忽略任何最新的检查。 如果是这种情况,只需使用--rerun任务。

你可能感兴趣的:(Using the Gradle Command-Line(2))