Gradle Effective Implementation Guide

Gradle Effective Implementation Guide
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
save 6%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Learn the best of Gradle
  • Work easily with multi-projects
  • Apply Gradle to your Java, Scala and Groovy projects

Book Details

Language : English
Paperback : 382 pages [ 235mm x 191mm ]
Release Date : October 2012
ISBN : 1849518106
ISBN 13 : 9781849518109
Author(s) : Hubert Klein Ikkink
Topics and Technologies : All Books, Application Development, Open Source

Table of Contents

Chapter 1: Starting with Gradle
Chapter 2: Creating Gradle Build Scripts
Chapter 3: Working with Gradle Build Scripts
Chapter 4: Using Gradle for Java Projects
Chapter 5: Dependency Management
Chapter 6: Testing, Building, and Publishing Artifacts
Chapter 7: Multi-project Builds
Chapter 8: Mixed Languages
Chapter 9: Maintaining Code Quality
Chapter 10: Writing Custom Tasks and Plugins
Chapter 11: Using Gradle with Continuous Integration
Chapter 12: IDE Support
  • Chapter 1: Starting with Gradle
    • Introducing Gradle
      • Declarative builds and convention over configuration
      • Support for Ant tasks and Maven repositories
      • Incremental builds
      • Multi-project builds
      • Gradle wrapper
      • Free and open source
    • Getting started
      • Installing Gradle
    • Writing our first build script
    • Default Gradle tasks
    • Task name abbreviation
    • Executing multiple tasks
    • Command-line options
      • Logging options
      • Changing the build file and directory
      • Running tasks without execution
      • Gradle daemon
      • Profiling
    • Understanding the Gradle user interface
      • Task Tree
      • Favorites
      • Command Line
      • Setup
    • Summary
    • Chapter 2: Creating Gradle Build Scripts
      • Writing a build script
      • Defining tasks
        • Defining actions with the Action interface
      • Build scripts are Groovy code
      • Defining dependencies between tasks
        • Defining dependencies via tasks
        • Defining dependencies via closures
      • Setting default tasks
      • Organizing tasks
        • Adding a description to tasks
        • Grouping tasks together
      • Adding tasks in other ways
        • Using task rules
      • Accessing tasks as project properties
      • Adding additional properties to tasks
      • Avoiding common pitfalls
      • Skipping tasks
        • Using onlyIf predicates
        • Skipping tasks by throwing StopExecutionException
        • Enabling and disabling tasks
        • Skipping from the command line
        • Skipping tasks that are up-to-date
      • Summary
      • Chapter 3: Working with Gradle Build Scripts
        • Working with files
          • Locating files
          • Using file collections
          • Working with file trees
          • Copying files
            • Renaming files
            • Filtering files
          • Archiving files
        • Project properties
          • Defining custom properties in script
          • Passing properties via the command line
          • Defining properties via system properties
          • Adding properties via environment variables
          • Defining properties using an external file
        • Using logging
          • Controlling output
        • Using the Gradle wrapper
          • Creating wrapper scripts
          • Customizing the Gradle wrapper
        • Summary
        • Chapter 4: Using Gradle for Java Projects
          • Using plugins
          • Getting started
          • Using the Java plugin
          • Working with source sets
            • Creating a new source set
            • Custom configuration
          • Working with properties
          • Creating documentation
          • Assembling archives
          • Summary
          • Chapter 5: Dependency Management
            • Dependency configuration
            • Repositories
              • Adding Maven repositories
              • Adding Ivy repositories
              • Adding a local directory repository
            • Defining dependencies
              • Using external module dependencies
              • Using project dependencies
              • Using file dependencies
              • Using client module dependencies
              • Using Gradle and Groovy dependencies
              • Accessing configuration dependencies
              • Setting dynamic versions
              • Resolving version conflicts
              • Adding optional ANT tasks
              • Using dependency configurations as files
            • Summary
            • Chapter 6: Testing, Building, and Publishing Artifacts
              • Testing
                • Using TestNG for testing
                • Configuring the test process
                • Determining tests
                • Logging test output
                • Generating test reports
              • Running Java applications
                • Running an application from a project
                • Running an application as task
                • Running an application with the application plugin
                • Creating a distributable application archive
              • Publishing artifacts
                • Uploading to a Maven repository
                • Multiple artifacts
                • Signing artifacts
                  • Publishing signature files
                  • Configuring conditional signing
              • Packaging Java Enterprise Edition applications
                • Creating a WAR file
                  • Using the War plugin
                • Creating an EAR file
                  • Using the Ear plugin
              • Summary
              • Chapter 7: Multi-project Builds
                • Working with multi-project builds
                  • Executing tasks by project path
                  • Using a flat layout
                  • Defining projects
                  • Filtering projects
                  • Defining task dependencies between projects
                  • Defining configuration dependencies
                • Working with Java multi-project builds
                  • Using partial builds
                • Using the Jetty plugin
                • Summary
                • Chapter 8: Mixed Languages
                  • Using the Groovy plugin
                    • Creating documentation with the Groovy plugin
                  • Using the Scala plugin
                    • Creating documentation with the Scala plugin
                  • Summary
                  • Chapter 9: Maintaining Code Quality
                    • Using the Checkstyle plugin
                    • Using the PMD plugin
                    • Using the FindBugs plugin
                    • Using the JDepend plugin
                    • Using the CodeNarc plugin
                    • Using the Sonar plugin
                    • Summary
                    • Chapter 10: Writing Custom Tasks and Plugins
                      • Creating a custom task
                        • Creating a custom task in the build file
                        • Using incremental build support
                      • Creating a task in the project source directory
                        • Writing tests
                      • Creating a task in a standalone project
                      • Creating a custom plugin
                        • Creating a plugin in the build file
                      • Creating a plugin in the project source directory
                        • Testing a plugin
                      • Creating a plugin in a standalone project
                      • Summary
                      • Chapter 11: Using Gradle with Continuous Integration
                        • Creating a sample project
                        • Using Jenkins
                          • Adding the Gradle plugin
                          • Configuring Jenkins job
                          • Running the job
                          • Configuring artifacts and test results
                          • Adding Gradle versions
                        • Using JetBrains TeamCity
                          • Creating a project
                          • Running the project
                        • Using Atlassian Bamboo
                          • Defining a build plan
                          • Running the build plan
                        • Summary
                        • Chapter 12: IDE Support
                          • Using the Eclipse plugin
                            • Customizing generated files
                              • Customizing using DSL
                              • Customizing with merge hooks
                              • Customizing with XML manipulation
                            • Merging configuration
                            • Configuring WTP
                              • Customizing file generation
                          • Using the IntelliJ IDEA plugin
                            • Customizing file generation
                              • Customizing using DSL
                              • Customizing with merged hooks
                              • Customizing with XML manipulation
                          • Running Gradle in Eclipse
                            • Installing Gradle plugin
                            • Importing Gradle project
                            • Running tasks
                            • Editing build files
                          • Running Gradle in IntelliJ IDEA
                            • Installing the plugin
                            • Importing a project
                            • Running tasks
                          • Summary

                          Hubert Klein Ikkink

                          Hubert Klein Ikkink was born in 1973 and lives in Tilburg, the Netherlands, with his beautiful wife and gorgeous children. He is also known as mrhaki, which is simply the initials of his name prepended by mr. He studied Information Systems and Management at the Tilburg University. After finishing his studies he started to work at a company which specialized in knowledge-based software. There he started writing his first Java software (yes, an applet!) in 1996. Over the years his focus switched from applets, to servlets, to Java Enterprise Edition applications, to Spring-based software. In 2008 he wanted to have fun again when writing software. The larger projects he was working on were more about writing configuration XML files, tuning performance and less about real development in his eyes. So he started to look around and noticed Groovy as a good language to learn about. He could still use existing Java code, libraries, and his Groovy classes in Java. The learning curve isn’t steep and to support his learning phase he wrote down interesting Groovy facts in his blog with the title Groovy Goodness. He posts small articles with a lot of code samples to understand how to use Groovy. Since November 2011 he is also a DZone Most Valuable Blogger (MVB); DZone also posts his blog items on their site. In 2010, 2011, and 2012 Hubert was invited to speak at Gr8Conf in Copenhagen, Denmark. This is a very good conference with all the project leaders of Groovy and Groovy-related projects. In November 2010 he presented a Gradle talk at the J-Fall conference of the Dutch Java User Group. In November 2011 he presented about the new features in Groovy 1.8 at the same conference. The conference is visited by 1000 Java developers and he got the chance to educate some of them about the greatness of Gradle and Groovy. Hubert works for a company called JDriven in the Netherlands. JDriven focuses on technologies that simplify and improve development of enterprise applications. Employees of JDriven have years of experience with Java and related technologies and are all eager to learn about new technologies. Hubert works on projects using Grails and Java combined with Groovy and Gradle.
                          Sorry, we don't have any reviews for this title yet.

                          Code Downloads

                          Download the code and support files for this book.

                          Submit Errata

                          Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                          - 1 submitted: last submission 28 May 2013

                          Errata type: Others | Page number: 72

                          Line 11 in code should read println project.ext.customProperty


                          Errata type: Code| Page number: 20

                          After renaming the build file to, the command to execute should be gradle --build-file -q helloWorld.


                          Errata type: Typo| Page number: 75

                          In the table describing the log levels and their usage, the usage description of QUIET is wrong : the word Import should read Important


                          Errata type: Typo| Page number: 75

                          At top of page, there are 3 'println' in the example, but only two results with the word 'custom' are printed at lines 9 and 10. There should be another line with the single word 'custom' inserted at line 11.


                          Errata type: Typo| Page number: 68

                          There is a missing period at end of second line from the top.



                          Errata type: Typo| Page number: 63

                          There is a missing closing curly brace, }, at the end of the seventh line from the end of page. It should go after the word 'relativePath' but before the double quote


                          Errata type: Code| Page number: 61

                          The error is on page 61 in chapter 3, the example for using a filtered collection. The example does not corresponds to the text of the paragraph and the example does not work as expected, in the sense that it does not show a live filtered collection working : when "rootFiles = rootFiles + files('LICENSE.txt')" is executed, a new instance of a FileCollection is made and the "smallFiles" filtered collection stays on the old collection and thus does *not* contain the added 'LICENSE.txt'.

                          This would fix the example :

                          task 'filterFiles' << {

                              def rootFiles = files('INSTALL.txt', 'README')

                              // Filter for files having the filename extension .txt

                              def txtFiles = rootFiles.filter {




                          // txtFiles now contains 2 files : INSTALL.txt and LICENSE.txt

                          println txtFiles.asPath




                          Errata type: Typo| Page number: 63

                          Line 5 of build15.gradle is missing the ending brace for fileDetails.relativePath before the "


                          Sample chapters

                          You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                          Frequently bought together

                          Gradle Effective Implementation Guide +    JIRA 4 Essentials =
                          50% Off
                          the second eBook
                          Price for both: $44.10

                          Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                          What you will learn from this book

                          • Create Gradle build scripts from clear examples
                          • Write build logic with the Gradle build language
                          • Compile, test and check your Java, Scala and Groovy applications
                          • Write your own custom tasks and plugins
                          • Use Gradle on continous integrations servers Jenkins, TeamCity and Bamboo
                          • Integrate Gradle with Eclipse and IntelliJ IDEA

                          In Detail

                          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.


                          Written in Packt's tutorial format the hands on examples and real life applications that will guide you through Gradle and give you the knowledge to use it every day.

                          Who this book is for

                          If you are a Java developer who wants to automate compiling, packaging and deploying your application this book is for you.

                          Code Download and Errata
                          Packt Anytime, Anywhere
                          Register Books
                          Print Upgrades
                          eBook Downloads
                          Video Support
                          Contact Us
                          Awards Voting Nominations Previous Winners
                          Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                          Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software