Gradle2.0用户指南翻译——第十二章. 使用Gradle 图形用户界面

时间:2022-11-08 09:12:27
翻译项目请关注Github上的地址:
https://github.com/msdx/gradledoc
本文翻译所在分支:
https://github.com/msdx/gradledoc/tree/2.0 。
在线浏览地址:
http://gradledoc.qiniudn.com/2.0/userguide/userguide.html 。
另外,Android 手机用户可通过我写的一个程序浏览文档,带缓存功能的,目前0.6开发中版本兼容 Android 2.3以上系统,项目地址如下:
https://github.com/msdx/gradle-doc-apk
翻译不易,转载请注明本文在CSDN博客上的出处:
http://blog.csdn.net/maosidiaoxian/article/details/78840754

关于我对Gradle的翻译,以Github上的项目及http://gradledoc.qiniudn.com 上的文档为准。如发现翻译有误的地方,将首先在以上两个地方更新。因时间精力问题,博客中发表的译文基本不会同步修改。


第十二章. 使用Gradle 图形用户界面

Chapter 12. Using the Gradle Graphical User Interface

除了支持传统的命令行界面,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.

示例12.1. 启动GUI - Example 12.1. Launching the GUI

gradle --gui

请注意,这个命令会被一直阻塞直到Gradle GUI被关闭。在*nix下,最好是将其作为后台任务运行(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.

图12.1. GUI任务树 - Figure 12.1. GUI Task Tree

Gradle2.0用户指南翻译——第十二章. 使用Gradle 图形用户界面

最好是在Gradle项目目录运行此命令,这样对UI的设置就可以保存在项目的目录中。不过,你也可以先运行它,然后通过UI中的“设置”选项卡来更改工作目录。 
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.

这里还提供了一个过滤器,可以隐藏不常见的任务。你可以通过“过滤器”按钮切换过滤器。编辑过滤器可以配置显示哪些任务和项目。隐藏的任务显示为红色。注意:新创建的任务默认情况下是显示状态(而不是默认隐藏)。 
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).

  • 将任务添加到收藏夹(见收藏夹Favorites选项卡)

    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.

图 12.2. GUI 设置 - Figure 12.2. GUI Setup

Gradle2.0用户指南翻译——第十二章. 使用Gradle 图形用户界面
  • 当前目录

    定义了 Gradle 项目的根目录(通常是 build.gradle 所在的位置)。

    Current Directory

    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 执行器 - 高级功能

    它为你提供了启动Gradle命令的替代方式。如果你的项目需要在另一个批处理文件或 shell 脚本中做一些额外的配置(比如指定一个初始化脚本),这将会非常有用。

    Use Custom Gradle Executor - Advanced feature

    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).