Gradle第十二章:使用Gradle 圖形用戶界面

除了支持傳統的命令行界面,Gradle也提供了一個圖形用戶界面(GUI)。這是一個獨立的用戶界面,可以通過加上 --gui 參數來啓動。 
In addition to supporting a traditional command line interface, Gradle offers a graphical user interface. This is a stand alone user interface that can be launched with the --gui option.

Example 12.1. Launching the GUI

gradle --gui

注意:此命令行窗口被將鎖定,直到Gradle GUI被關閉。如果是在linux/unix系統下,則可以通過 ( gradle --gui& )讓它作爲後臺任務運行。 
Note that this command blocks until the Gradle GUI is closed. Under *nix it is probably preferable to run this as a background task ( gradle --gui& )

如果你在你的Gradle項目目錄下運行Gradle GUI,你應該會看到一個任務樹。 
If you run this from your Gradle project working directory, you should see a tree of tasks.

Figure 12.1. GUI Task Tree

GUI Task Tree

最好是從Gradle項目目錄運行此命令,這樣對UI的設置就可以存儲在你的項目目錄中。當然,你也可以先運行它,然後通過在UI中的設置(Setup)選項卡,改變工作目錄。 
It is preferable to run this command from your Gradle project directory so that the settings of the UI will be stored in your project directory. However, you can run it then change the working directory via the Setup tab in the UI.

在Gradle的用戶界面(UI)中,上面是4個選項卡,下面則是輸出窗口。 
The UI displays 4 tabs along the top and an output window along the bottom.

12.1. 任務樹

12.1. Task Tree

任務樹顯示了所有項目和它們的任務的層次結構。雙擊一個任務可以執行它。 
The Task Tree shows a hierarchical display of all projects and their tasks. Double clicking a task executes it.

這裏還提供了一個過濾器,可以把比較少用的任務隱藏。你可以通過過濾器(Filter)按鈕切換是否進行過濾。通過編輯過濾器,你可以對哪些任務和項目要顯示進行配置。隱藏的任務顯示爲紅色。注意:新創建的任務默認情況下是顯示狀態(而不是隱藏狀態) 
There is also a filter so that uncommon tasks can be hidden. You can toggle the filter via the Filter button. Editing the filter allows you to configure which tasks and projects are shown. Hidden tasks show up in red. Note: newly created tasks will show up by default (versus being hidden by default).

任務樹的上下文菜單會提供以下選項: 
The Task Tree context menu provides the following options:

  • 執行忽略依賴關係。這使得重新構建時不去依賴項目(與-a選項一樣) 
    Execute ignoring dependencies. This does not require dependent projects to be rebuilt (same as the -a option).

  • 將任務添加到收藏夾(見收藏夾(Favourites)選項卡) 
    Add tasks to the favorites (see Favorites tab)

  • 隱藏選擇的任務。這將會把它們添加到過濾器中。 
    Hide the selected tasks. This adds them to the filter.

  • 編輯 build.gradle 文件。注意:該操作需要 Java 1.6 或更高的版本,並且要求在你的操作系統中關聯 gradle 文件。 
    Edit the build.gradle file. Note: this requires Java 1.6 or higher and requires that you have .gradle files associated in your OS.

12.2. 收藏夾

12.2. Favorites

收藏夾選項卡用來儲存經常執行的命令。這些命令可以是複雜的命令(只要它們符合 Gradle 的語法),你可以給它們設置一個顯示名稱。它用於創建一個自定義的命令,來顯示地跳過測試,文檔,例子。你可以稱之爲“快速構建”。 
The Favorites tab is place to store commonly-executed commands. These can be complex commands (anything that's legal to Gradle) and you can provide them with a display name. This is useful for creating, say, a custom build command that explicitly skips tests, documentation, and samples that you could call "fast build".

你可以根據自己的喜好,對收藏夾進行排序,甚至可以把它們導出到磁盤,並在其他地方導入。如果你在編輯它們的時候,選上“始終顯示實時輸出”,它只有在你選上“當發生錯誤時才顯示輸出”時有效。它會始終強制顯示輸出。 
You can reorder favorites to your liking and even export them to disk so they can imported by others. If you edit them, you are given options to "Always Show Live Output." This only applies if you have 'Only Show Output When Errors Occur'. This override always forces the output to be shown.

12.3. 命令行

12.3. Command Line

命令行選項卡是直接執行單個的 Gradle 命令的地方。你只需要輸入命令行中你經常在“Gradle”後面輸入的命令即可。它也對要添加到收藏夾的命令提供了先去嘗試的地方。 
The Command Line tab is place to execute a single Gradle command directly. Just enter whatever you would normally enter after 'gradle' on the command line. This also provides a place to try out commands before adding them to favorites.

12.4. 設置

12.4. Setup

設置(Setup)選項卡允許你配置一些常規的設置。 
The Setup tab allows configuration of some general settings.

Figure 12.2. GUI Setup

GUI Setup
  • 當前目錄 
    Current Directory

    定義了你的 Gradle 項目(通常是 build.gradle 所在的位置)的根目錄。 
    Defines the root directory of your Gradle project (typically where build.gradle is located).

  • 堆棧跟蹤輸出 
    Stack Trace Output

    這決定了當出現錯誤時,有多少信息定到堆棧跟蹤。注意:如果你在命令行或收藏夾選項卡上指定了堆棧跟蹤級別,將會覆蓋這裏的設置。 
    This determines how much information to write out stack traces when errors occur. Note: if you specify a stack trace level on either the Command Line or Favorites tab, it will override this stack trace level.

  • 只在出現錯誤時顯示輸出 
    Only Show Output When Errors Occur

    啓用此選項將在任務執行時隱藏任何輸出,除非構建失敗。 
    Enabling this option hides any output when a task is executed unless the build fails.

  • 使用自定義的 Gradle 執行器 - 高級功能 
    Use Custom Gradle Executor - Advanced feature

    這爲你提供了啓動 Gradle 命令行的替代方法。這是很有用的。如果你的項目需要在另一個批處理文件或 shell 腳本中做一些額外的配置(比如指定一個初始化腳本)。 
    This provides you with an alternate way to launch Gradle commands. This is useful if your project requires some extra setup that is done inside another batch file or shell script (such as specifying an init script).

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章