Book Image

Gradle Effective Implementation Guide

Book Image

Gradle Effective Implementation Guide

Overview of this book

Gradle is the next generation in build automation. It uses convention-over-configuration to provide good defaults, but is also flexible enough to be usable in every situation you encounter in daily development. Build logic is described with a powerful DSL and empowers developers to create reusable and maintainable build logic."Gradle Effective Implementation Guide" is a great introduction and reference for using Gradle. The Gradle build language is explained with hands on code and practical applications. You learn how to apply Gradle in your Java, Scala or Groovy projects, integrate with your favorite IDE and how to integrate with well-known continuous integration servers.Start with the foundations and work your way through hands on examples to build your knowledge of Gradle to skyscraper heights. You will quickly learn the basics of Gradle, how to write tasks, work with files and how to use write build scripts using the Groovy DSL. Then as you develop you will be shown how to use Gradle for Java projects. Compile, package, test and deploy your applications with ease. When you've mastered the simple, move on to the sublime and integrate your code with continuous integration servers and IDEs. By the end of the "Gradle Effective Implementation Guide" you will be able to use Gradle in your daily development. Writing tasks, applying plugins and creating build logic will be second nature.
Table of Contents (20 chapters)
Gradle Effective Implementation Guide
About the Author
About the Reviewers

Understanding the Gradle user interface

Finally, we take a look at the --gui command-line option. With this option, we start a graphical shell for our Gradle builds. Until now, we have used the command line to start a task. With the Gradle GUI, we have a graphical overview of the tasks in a project, and we can execute them by simply double-clicking on them.

To start the GUI, we invoke the following command:

hello-world $ gradle --gui

A window is opened with a graphical overview of our task tree. We have only one task, which is listed in the task tree, as shown in the following screenshot:

The output of a running task is shown in the bottom part of the window. When we start the GUI for the first time, the tasks task is executed and we see the output in the window.

Task Tree

The Task Tree tab shows projects and tasks found in our build project. We can execute a task by double-clicking on the task name.

By default all tasks are shown, but we can apply a filter to show or hide certain projects and tasks. The Filter button opens a new dialog window where we can define which tasks and properties are part of the filter. The Toggle filter button makes the filter active or inactive.

We can also right-click on the project and task names. This opens a context menu where we can choose whether to execute the task, add it to the favorites, hide it (adds it to the filter), or edit the build file. If we click on Edit File, and if the .gradle extension is associated with a text editor in our operating system, the editor is opened with the content of the build script. These options can be seen in the following screenshot:


The Favorites tab stores tasks we want to execute regularly. We can add a task by right-clicking on the task in the Task Tree tab and selecting the Add To Favorites menu option. Alternatively, we can open the Favorites tab, click on the Add button and manually enter the project and task name we want to add to our favorites list. We can see the Add Favorite dialog window in the following screenshot:

Command Line

On the Command Line tab, we can enter any Gradle command we normally would enter on the command prompt. The command can be added to Favorites as well. We can see the Command Line tab contents in the following screenshot:


The last tab is the Setup tab. Here, we can change the project directory, which is set by default to the current directory.

We learned about the different logging levels as command-line options previously in this chapter. In the GUI, we can select the logging level from the Log Level drop-down box with the different log levels. We can choose one of Debug, Info, Lifecyle, and Error as the log levels. The Error log level only shows errors and is the least verbose, while Debug is the most verbose log level. The Lifecyle log level is the default log level.

Here we can also set how detailed the exception stack trace information should be. In the section Stack Trace Output we can choose between the following three options:

  • Exceptions only: For showing only exceptions when they occur; this is the default value

  • Standard Stack Trace: For showing more stack trace information for the exceptions

  • Full Stack Trace: For the most verbose stack trace information for exceptions

If we enable the option Only Show Output When Errors Occur, we get output from the build process only if the build fails; otherwise we don't get any output.

Finally, we can define a different way to start Gradle for the build, with the option Use Custom Gradle Executor . For example, we can define a different batch or script file with extra setup information to run the build process. The following screenshot shows the Setup tab page along with all the options we can set: