O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building and Testing with Gradle

Book Description

Build and test software written in Java and many other languages with Gradle, the open source project automation tool that’s getting a lot of attention. This concise introduction provides numerous code examples to help you explore Gradle, both as a build tool and as a complete solution for automating the compilation, test, and release process of simple and enterprise-level applications.

Discover how Gradle improves on the best ideas of Ant, Maven, and other build tools, with standards for developers who want them and lots of flexibility for those who prefer less structure.

  • Use Gradle with Groovy, Clojure, Scala, and languages beyond the JVM, such as Flex and C
  • Get started building a simple Java program using Gradle's command line tooling and a small build script
  • Learn how to configure and construct tasks, Gradle's fundamental unit of build activity
  • Take advantage of Gradle's integration with Ant
  • Use Gradle to integrate with or transition from Maven, and to build software more cleanly
  • Perform application unit and integration tests using JUnit, TestNG, Spock, and Geb

Table of Contents

  1. Dedication
  2. Foreword
  3. Preface
    1. Introduction
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments from Tim Berglund
    7. Acknowledgments from Matthew McCullough
  4. 1. Hello, Gradle!
    1. Build Files in Groovy
    2. Domain-Specific Build Languages
    3. Getting Started
      1. MacOS Installation with Brew
      2. Linux and MacOS Installation
      3. Windows Installation
    4. The Hello World Build File
    5. Building a Java Program
    6. The Gradle Command Line
  5. 2. Gradle Tasks
    1. Declaring a Task
    2. Task Action
    3. Task Configuration
    4. Tasks Are Objects
      1. Methods of DefaultTask
        1. dependsOn(task)
        2. doFirst(closure)
        3. doLast(closure)
        4. onlyIf(closure)
      2. Properties of DefaultTask
        1. didWork
        2. enabled
        3. path
        4. logger
        5. logging
        6. description
        7. temporaryDir
      3. Dynamic Properties
    5. Task Types
      1. Copy
      2. Jar
      3. JavaExec
    6. Custom Task Types
      1. Custom Tasks Types in the Build File
      2. Custom Tasks in the Source Tree
    7. Where Do Tasks Come From?
    8. Conclusion
  6. 3. Ant and Gradle
    1. The Vocabulary
    2. Hello Ant
    3. Importing Custom Ant Tasks
    4. Complex Ant Configuration
    5. Importing an Entire Ant Build File
    6. Ant Target and Gradle Task Codependence
    7. Using AntBuilder
    8. A Harmonic Duo
  7. 4. Maven and Gradle
    1. Cue Graven?
    2. The Maven POM and Gradle Build
    3. Maven Goals, Gradle Tasks
    4. The Standard Maven Coordinates, Gradle Properties
    5. More Gradle Properties
    6. Dependencies
    7. Repositories
    8. Unit Testing
    9. Multiple Source Directories
    10. Default Tasks
    11. The Maven Plug-in
    12. Installing to the Local Maven Repository (Cache)
    13. Publishing to a Maven Repository
    14. Maven2Gradle Build Script Converter
    15. Maven POM Import
    16. Conclusion
  8. 5. Testing with Gradle
    1. JUnit
    2. TestNG
    3. Spock
    4. Geb and EasyB
    5. Gradle’s Testing Focus
  9. 6. Multiproject Builds
    1. Multiproject Build Structure
    2. Project-Specific Build Files
    3. One Master Build File
    4. A Hybrid Multiproject Build
    5. Individual, Unified, or Hybrid?
    6. Multiproject Task Structure
    7. Multiple Projects Your Way
  10. About the Authors
  11. Colophon
  12. Copyright