gradle--第十一章 使用Gradle命令行2

来源:互联网 发布:类的定义 c语言 编辑:程序博客网 时间:2024/05/20 11:33
11.6 获取你构建的信息
Gradle提供了几个内置的大人物来显示一些你构建的详细信息。这个对理解你的工程构建,依赖和调试为你痛是非常有帮助的。
除了下面列出的一些内置任务,你也可以使用project report 插件来添加任务到你的工程,这些任务也会产生这些报表。
11.6.1 显示工程
运行gradle projects会以一个层次的方式显示选择工程的一个子工程的列表,如:
Example 11.7. Obtaining information about projects


Output of gradle -q projects
> gradle -q projects


------------------------------------------------------------
Root project
------------------------------------------------------------


Root project 'projectReports'
+--- Project ':api' - The shared API for the application
\--- Project ':webapp' - The Web application implementation


To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :api:tasks
如果这个工程有详细信息的话,这个报表显示了各个工程的详细信息。你可以通过设置工程的描述属性来为工程设置一个描述。
Example 11.8. Providing a description for a project


build.gradle
description = 'The shared API for the application'
11.6.2 显示任务
运行gradle tasks将会显示选择工程的一个主要任务信息列表。这个报表显示工程的缺省任务,如果有描述信息的话,也会显示。如下这个例子:
Example 11.9. Obtaining information about tasks


Output of gradle -q tasks
> gradle -q tasks


------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------


Default tasks: dists


Build tasks
-----------
clean - Deletes the build directory (build)
dists - Builds the distribution
libs - Builds the JAR


Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]


Help tasks
----------
components - Displays the components produced by root project 'projectReports'. [incubating]
dependencies - Displays all dependencies declared in root project 'projectReports'.
dependencyInsight - Displays the insight into a specific dependency in root project 'projectReports'.
help - Displays a help message.
model - Displays the configuration model of root project 'projectReports'. [incubating]
projects - Displays the sub-projects of root project 'projectReports'.
properties - Displays the properties of root project 'projectReports'.
tasks - Displays the tasks runnable from root project 'projectReports' (some of the displayed tasks may belong to subprojects).


To see all tasks and more detail, run gradle tasks --all


To see more detail about a task, run gradle help --task <task>
默认的,这个报表只显示这些分配到一个任务组的任务。你也可以通过设置组属性来把任务关联到一个组。你同样也可以设置描述属性,来在报表中提供一个描述。
Example 11.10. Changing the content of the task report


build.gradle
dists {
    description = 'Builds the distribution'
    group = 'build'
}
你可以通过该-all选项来获取更多关于显示任务方面的信息。使用这个选项,报表将会显示一个工程中的所有任务,以主要任务进行分组,以及各个任务的依赖,如:
Example 11.11. Obtaining more information about tasks


Output of gradle -q tasks --all
> gradle -q tasks --all


------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------


Default tasks: dists


Build tasks
-----------
clean - Deletes the build directory (build)
api:clean - Deletes the build directory (build)
webapp:clean - Deletes the build directory (build)
dists - Builds the distribution [api:libs, webapp:libs]
    docs - Builds the documentation
api:libs - Builds the JAR
    api:compile - Compiles the source files
webapp:libs - Builds the JAR [api:libs]
    webapp:compile - Compiles the source files


Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]


Help tasks
----------
components - Displays the components produced by root project 'projectReports'. [incubating]
api:components - Displays the components produced by project ':api'. [incubating]
webapp:components - Displays the components produced by project ':webapp'. [incubating]
dependencies - Displays all dependencies declared in root project 'projectReports'.
api:dependencies - Displays all dependencies declared in project ':api'.
webapp:dependencies - Displays all dependencies declared in project ':webapp'.
dependencyInsight - Displays the insight into a specific dependency in root project 'projectReports'.
api:dependencyInsight - Displays the insight into a specific dependency in project ':api'.
webapp:dependencyInsight - Displays the insight into a specific dependency in project ':webapp'.
help - Displays a help message.
api:help - Displays a help message.
webapp:help - Displays a help message.
model - Displays the configuration model of root project 'projectReports'. [incubating]
api:model - Displays the configuration model of project ':api'. [incubating]
webapp:model - Displays the configuration model of project ':webapp'. [incubating]
projects - Displays the sub-projects of root project 'projectReports'.
api:projects - Displays the sub-projects of project ':api'.
webapp:projects - Displays the sub-projects of project ':webapp'.
properties - Displays the properties of root project 'projectReports'.
api:properties - Displays the properties of project ':api'.
webapp:properties - Displays the properties of project ':webapp'.
tasks - Displays the tasks runnable from root project 'projectReports' (some of the displayed tasks may belong to subprojects).
api:tasks - Displays the tasks runnable from project ':api'.
webapp:tasks - Displays the tasks runnable from project ':webapp'.
11.6.3 显示任务详细信息
运行gradle help --task someTask命令可以显示在你构建的多工程中的一个或多个匹配给定任务的详细信息,如下就是关于详细信息的一个例子:
Example 11.12. Obtaining detailed help for tasks


Output of gradle -q help --task libs
> gradle -q help --task libs
Detailed task information for libs


Paths
     :api:libs
     :webapp:libs


Type
     Task (org.gradle.api.Task)


Description
     Builds the JAR


Group
     build
显示的的信息包括任务的全路径,任务的类型,可选的命令行选项以及给定任务的描述信息。
11.6.4 显示工程依赖
运行gradle dependencies将会显示选择工程的一个依赖列表,依赖于配置。对于每个配置,直接和间接的依赖都会显示在另一个树上,如下是一个这方面的报表:
 Example 11.13. Obtaining information about dependencies


Output of gradle -q dependencies api:dependencies webapp:dependencies
> gradle -q dependencies api:dependencies webapp:dependencies


------------------------------------------------------------
Root project
------------------------------------------------------------


No configurations


------------------------------------------------------------
Project :api - The shared API for the application
------------------------------------------------------------


compile
\--- org.codehaus.groovy:groovy-all:2.3.10


testCompile
\--- junit:junit:4.12
     \--- org.hamcrest:hamcrest-core:1.3


------------------------------------------------------------
Project :webapp - The Web application implementation
------------------------------------------------------------


compile
+--- project :api
|    \--- org.codehaus.groovy:groovy-all:2.3.10
\--- commons-io:commons-io:1.2


testCompile
No dependencies
由于一个依赖报表可能变的非常大,这对于限制一个报表为某个特定的配置非常有用。这个可以通过--configuration参数来达到:
Example 11.14. Filtering dependency report by configuration


Output of gradle -q api:dependencies --configuration testCompile
> gradle -q api:dependencies --configuration testCompile


------------------------------------------------------------
Project :api - The shared API for the application
------------------------------------------------------------


testCompile
\--- junit:junit:4.12
     \--- org.hamcrest:hamcrest-core:1.3
 
 
 
0 0