1. 程式人生 > >【Gradle Build Tool 4.1使用者指南】Chapter 5.The Gradle Console

【Gradle Build Tool 4.1使用者指南】Chapter 5.The Gradle Console

5.1. Overview 概述

Nearly every Gradle user will experience the command-line interface at some point. Gradle’s console output is optimized for rendering performance and usability, showing only relevant information and providing visually appealing feedback.

幾乎每個Gradle使用者都會在某個時刻體驗到命令列介面。為了增強表現力和具備實用性,Gradle的控制檯輸出被進行了優化:只顯示相關資訊和視覺上有吸引力的反饋資訊。

Figure 5.1. The Gradle command-line in action 活動狀態的Gradle命令列


5.2. Command-line feedback 命令列反饋

Gradle displays information while the build is running so you can concentrate on the most important items of interest. Each of the sections of Gradle’s console output help answer specific questions.

當構建正在進行時,

Gradle會顯示相關資訊,所以你可以集中精力在最重要的專案上面。Gradle控制檯輸出的每個部分,都能幫助解決一些具體問題。

Is there anything I should know about my build right now e.g. tests have failed and emitted warnings?

現在有沒有一些關於我的構建的資訊,比如:任務失敗和警告資訊?

When will my build finish? 構建什麼時候結束?

What is Gradle doing right now? Gradle現在在執行嗎?

Are there other interesting outcomes e.g. tasks that have been skipped or were up-to-date?

有沒有其他需要注意的情況出現。比如任務被跳過或up-to-date?

5.2.1. Build output 構建輸出

Output from build script log messages, tasks, forked processes, test output and compile warnings is displayed above the build progress bar.

構建指令碼的log資訊,任務,程序,測試輸出和編譯警告的輸出都會呈現於構建進度條的上面。

Figure 5.2. Build output portion of the Gradle command-line Gradle命令列的部分構建輸出


Starting with Gradle 4.0, the volume of command-line console output has been reduced. The start and end of each task is not displayed anymore or the outcome of the task (e.g. UP-TO-DATE). The task’s name is only displayed if some output is emitted during task execution. Gradle also groups output originating from a specific context together, e.g. all warnings from a compilation task, test execution or forked processes. Grouped output is especially useful for parallel task execution, as it prevents interleaved messages that do not clearly indicate their origin (see Section 26.8, “Parallel project execution”).

Gradle 4.0開始,命令列控制檯的量輸出就被減少了。每個任務的開始和結束不再顯示,或者不顯示某些任務(例如:UP-TO-DATE)。如果在任務執行過程中有一些輸出,也只是顯示任務的名字。Gradle還從一個特定的上下文中組織輸出源,比如來自編譯任務的所有警告,測試執行或者分叉過程。分組輸出對並行任務執行是特別有用的,因為它防止了資訊的交錯——不能清楚地表明來源(見第26.8節,“平行專案執行”)。

The following console output shows grouped output for the configuration phase and the task :compileJava: 以下的控制檯輸出顯示了配置階段和任務compileJava的組輸出:

> Configure project ':library'
Configuring project version for project ':library'
> Configure project ':consumer'
Configuring project version for project ':consumer'
> Task :compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Gradle does not wait until a unit of work is fully completed before displaying its output. Gradle flushes output to the console after a short amount of time to ensure that relevant information is made available as soon as possible. When building in parallel, the output of long running tasks can be broken up by other tasks. Each block of console output will clearly indicate which task it belongs to.

Gradle在工作還沒有全部完成之前就顯示輸出了。為確保儘快提供相關資訊,Gradle在很短的時間內就重新整理一次控制檯輸出。在並行構建的時候,長時間執行的任務輸出會被其他的任務輸出分開。所以,控制檯輸出的每個塊都將清楚指示出它屬於哪個任務。

> Task :compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :generateCode
Generating JAXB classed from XSD files.
> Task :compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

5.2.2. Build progress bar 構建進度條

The build progress bar gives you a very fast way of knowing if the build will be finished soon. As the build performs work, the progress bar will fill from left to right. At any given time, the build progress bar also renders the current phase of the build lifecycle (see Section 22.1, Build phases) and the overall time spent during the build.

構建進度條會讓你非常快速地知道構建是否很快就會完成。當構建進行時,進度條會隨著進度從左到右填充。在任意給定時間,構建進度條也呈現構建宣告週期的當前階段(見第22.1節,“構建階段”)以及在構建期間花費的總時間。

Figure 5.3. Build progress bar portion of the Gradle command-line

Gradle命令列中的構建進度條部分


 The following examples shows the progress bar during the initialization, configuration and execution phase of the build lifecycle:

下面的例子顯示了在構建宣告週期的初始化、配置和執行階段的進度條:

<-------------> 0% INITIALIZING [2s]
<==-----------> 25% CONFIGURING [4s]
<=========----> 64% EXECUTING [17s]

5.2.3. Work in-progress display 工作進行中的顯示

Gradle provides a fined-grained view of the actual work being performed directly underneath the The build progress bar. Each line represents a thread or process that can perform work in parallel—​resolving dependencies, executing a task and running tests. If an available worker is not being used then it is marked with IDLE. The number of available workers defaults to the number of processors on the machine executing the build.

Gradle在構建進度條下面為實際執行的工作提供了一個直觀細化的檢視。每一行表示一個執行緒或程序,它可以並行地解析依賴關係,執行任務和執行測試。如果一個工作模組沒有被使用,那麼它會被標誌為空閒。可用工作模組的數目和執行構建的機器上的處理器的數目不一致。

Figure 5.4. Work in-progress portion of the Gradle command-line 

Gradle命令列中正在工作的部分


Parallel test execution is only displayed for JVM-based tests supported by Gradle core e.g. JUnit and TestNG. Future versions of Gradle might support other testing tools and frameworks.

並行測試只有顯示以Gradle的核心支援的基於JVM的測試。例如JUnit和TestNG,Gradle的未來版本可能支援其他測試工具和框架。

The following portion of the console output shows the work in-progress display with 8 concurrent workers:

下面的部分控制檯輸出顯示了正在工作的8個工作模組。

<==========---> 77% EXECUTING [10s]
> :codeQuality:classpathManifest > Resolve dependencies :codeQuality:runtimeClasspath
> :ivy:classpathManifest > Resolve dependencies :ivy:runtimeClasspath
> IDLE
> :antlr:classpathManifest > Resolve dependencies :antlr:runtimeClasspath
> :scala:compileJava > Resolve dependencies :scala:compileClasspath
> :buildInit:classpathManifest > Resolve dependencies :buildInit:runtimeClasspath
> :jacoco:classpathManifest > Resolve dependencies :jacoco:runtimeClasspath
> IDLE

5.2.4. Build result 構建結果

At the end of the build, Gradle will display the result of the build (successful or failed) and the number of tasks that performed work and avoided work. The build result also displays the overall elapsed time it took to execute the build. The number of tasks that performed work provides an indication of how out-of-date or busy the build was.

在構建的最後,Gradle會顯示構建的結果(成功或失敗),以及,執行了的任何和跳過的任務的數目。構建結果還顯示了執行構建所需的總時間。執行工作模組的數目提供了構建是如何過時或忙碌的資訊。

Figure 5.5. Build progress bar portion of the Gradle command-line 

建立Gradle命令列的進度條部分


The following build result represents a successful build and the amount of tasks including their statuses:

下面的構建返回結果代表一個成功的構建和任務的數目包括它們的狀態:

BUILD SUCCESSFUL in 2m 10s
411 actionable tasks: 381 executed, 30 up-to-date

"Actionable" tasks are tasks with at least one action. Lifecycle tasks like build (also called aggregation tasks) do not declare any actions and are therefore not actionable.

“可操作”任務是至少有一個動作的任務。生命週期任務build(也叫聚合任務),不宣告任何操作,因此不可操作。

5.3. Look & feel in non-interactive environments 非互動性環境中的外觀和感覺

By default, Gradle tries to enable rich console output by detecting the type of console the build is running from. This enables color and additional console output formatting. Non-interactive environments fall back to using plain console output. The plain output format does not support grouping of output. Tasks and outcomes are always printed to be consistent with Gradle 3.x versions.

預設情況下,Gradle試圖通過檢測構建正在執行的控制檯的型別來啟用豐富的控制檯輸出。啟用了顏色和其他的控制檯輸出格式化。非互動式環境則使用普通的控制檯輸出。普通輸出格式不支援輸出分組。任務和結果的列印總是和Gradle 3.x版本的一致。

Gradle builds executed from an IDE (e.g. Buildship and IntelliJ) or Continuous Integration products (e.g. Jenkins and TeamCity) use plain console output by default.

IDE(如:Buildship和IntelliJ)或持續整合工具(如:Jenkins和TeamCity)的Gradle構建,都預設使用普通的控制檯輸出。

The following output demonstrates the use of a plain console:

下面展示了一個普通控制檯的使用:

:compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processResources
:classes
:jar
:assemble
:compileTestJava NO-SOURCE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:test NO-SOURCE
:check UP-TO-DATE
:build
 
BUILD SUCCESSFUL in 6s
11 actionable tasks: 6 executed, 5 up-to-date