4.4. Task name abbreviation(任务名称缩写)
When you specify tasks on the command-line, you don’t have to provide the full name of the task. You only need to provide enough of the task name to uniquely identify the task. For example, in the sample build above, you can execute task dist by running gradle di
当你在命令行指定任务时,不需要提供任务的全名。仅仅需要提供一个足以识别任务的唯一名称就行了。例如,在上面的例子中,执行dist任务只需要运行gradle di命令就可以了
> gradle di
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution
BUILD SUCCESSFUL
Total time: 1 secs
You can also abbreviate each word in a camel case task name. For example, you can execute task compileTest by running gradle compTest or even gradle cT
你也可以找到像驼峰一样的单词(java中方法和变量名命名规则,除首字母外每个单词首字母大写,就像是骆驼的驼峰一样有个最高点),按照首字母来指定名字,比如,你可以通过执行compTest或者cT执行任务compileTest。(当然也可以用coT等,只需要注意每个单词的首字母就行了,小写的小写,大写的大写)
> gradle cT
:compile
compiling source
:compileTest
compiling unit tests
BUILD SUCCESSFUL
Total time: 1 secs
You can also use these abbreviations with the -x command-line option.
你也可以在-x命令操作中使用缩写规则。(就是前面提到的排除命令)
4.5. Selecting which build to execute(选择执行哪一个build)
When you run the gradle command, it looks for a build file in the current directory. You can use the -b option to select another build file. If you use -b option then settings.gradle file is not used. Example:
当你执行gradle命令时,它会从当前目录寻找build文件(build.gradle文件)。你可以使用-b操作去选择另外一个build文件。如果你使用-b操作,那么settings.gradle文件就不会被用到了。
例如:
subdir/myproject.gradle
task hello << {
println "using build file '$buildFile.name' in '$buildFile.parentFile.name'."
}
昨天我在目录Chapter4.1中创建了第一个脚本build.gradle,现在我在这个目录同级创建一个Chapter4.2目录,编写一个myproject.gradle脚本文件,里面就定义上面的那个hello任务。目前我还在目录4.1中,
执行命令:gradle -b ../Chapter4.2/myproject.gradle hello
果然,这样是可以执行的,现在看来,这东西就跟一般的命令行一样,指定目录也是可以运行的,官网上的命令中用到了-q,这个-q其实是quiet的意思,也就是安静模式,不会输出不需要的内容,比如BUILD SUCCESSFUL.
具体的那些gradle后面跟的选项都有些什么,大家可以敲命令gradle -h进行查看。
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 -b option.
另外,你可以使用-p选项来指定要使用到的工程(project)目录。在多工程构建的时候,你需要用-p代替-b选项。
比如:
> gradle -q -p subdir hello
using build file 'build.gradle' in 'subdir'.
这里需要注意一点,使用这种方式,gradle文件名称必须为build.gradle
4.6. Obtaining information about your build(获取你的build信息)
Gradle provides several built-in tasks which show particular details of your build. This can be useful for understanding the structure and dependencies of your build, and for debugging problems.
gradle提供了几个用来显示你的build具体细节的内置任务。这些对于理解你的build结构和依赖项是非常有用的,还可以用来调试问题。
In addition to the built-in tasks shown below, you can also use the project report plugin to add tasks to your project which will generate these reports.
除了下面说到的内置任务之外,你还可以使用project report plugin 添加任务到你的工程中,那些添加了任务的工程将会生成这些报告。
点击上面的超链接,原来跳转到了project report plugin的相关页面,那下面就跟着去看看怎么回事吧!
Chapter 27. The Project Report Plugin
The Project report plugin adds some tasks to your project which generate reports containing useful information about your build. These tasks generate the same content that you get by executing the tasks
, dependencies
, and properties
tasks from the command line (see Section 4.6, “Obtaining information about your build”). In contrast to the command line reports, the report plugin generates the reports into a file. There is also an aggregating task that depends on all report tasks added by the plugin.
We plan to add much more to the existing reports and create additional ones in future releases of Gradle.
大概意思是说,这个插件可以添加一些任务到你的工程中,以达到生成一些包含你build信息的报告的目的。这些任务生成的内容和你执行tasks、dependencies还有properties等任务时是一样的。与命令行的区别是,这个插件生成的报告内容是放到一个文件中的。被这个插件添加的任务是一个依赖了所有的report任务的聚合任务。
我们计划去更新现有reports,在未来的版本中,也会增加更多的这些东西。
To use the Project report plugin, include the following in your build script:
使用project report plugin,需要添加以下代码在你的脚本中。
apply plugin: 'project-report'
The project report plugin defines the following tasks:
这里是目前project report plugin定义的一些任务。
Table 27.1. Project report plugin - tasks
Task name | Depends on | Type | Description |
dependencyReport | - | DependencyReportTask | Generates the project dependency report. |
htmlDependencyReport | - | HtmlDependencyReportTask | Generates an HTML dependency and dependency insight report for the project or a set of projects. |
propertyReport | - | PropertyReportTask | Generates the project property report. |
taskReport | - | TaskReportTask | Generates the project task report. |
projectReport | dependencyReport , propertyReport , taskReport , htmlDependencyReport | Task | Generates all project reports. |
The project report plugin does not require any particular project layout.
这东西并不需要什么具体的布局。
The project report plugin does not define any dependency configurations.
这东西不需要定义任何依赖项。
The project report defines the following convention properties:
Table 27.2. Project report plugin - convention properties
Property name | Type | Default value | Description |
reportsDirName | String | reports | The name of the directory to generate reports into, relative to the build directory. |
reportsDir | File (read-only) |
| The directory to generate reports into. |
projects | Set<Project> | A one element set with the project the plugin was applied to. | The projects to generate the reports for. |
projectReportDirName | String | project | The name of the directory to generate the project report into, relative to the reports directory. |
projectReportDir | File (read-only) |
| The directory to generate the project report into. |
These convention properties are provided by a convention object of type ProjectReportsPluginConvention
.
ProjectReportsPluginConvention
.