You are previewing Mastering Gradle.
O'Reilly logo
Mastering Gradle

Book Description

Master the technique of developing, migrating, and building automation using Gradle

In Detail

With Gradle, you can efficiently build automation framework along with some flexible alternatives to customized build logic. This book starts with sound basics about build automation and how Gradle fits into this automation. It then moves on to give you a good exposure on Groovy—a scripting language used to write Gradle—and helps you understand a key elements of Groovy programming language. In the following chapters, you will deal with task management and learn how to integrate Ant tasks into build scripts. Furthermore, you will learn dependency management, plugin management, and its configuration techniques in Gradle. You will also get hands-on with building and testing projects using Gradle. You will then begin to cover diverse topics, such as Continuous Integration with Jenkins and TeamCity, Migration strategies, and Deployment, which enables you to learn concepts useful for Agile software development. Finally, you will also learn how to create a simple mobile application using Android and explore how Gradle can help you to build and test the application.

What You Will Learn

  • Create and develop a build system with Gradle

  • Understand Groovy basics and key features to write Gradle scripts

  • Explore the important features of Gradle: task management, plugin management, and dependency management

  • Walkthrough various in-built Gradle plugins, such as Java, Scala, War, Ant, Maven, and many others

  • Master the migration techniques from build tools such as Ant and Maven into Gradle

  • Integrate Gradle with popular continuous integration tools such as Jenkins and TeamCity

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Mastering Gradle
      1. Table of Contents
      2. Mastering Gradle
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Getting Started with Gradle
        1. Understanding Build Automation System
          1. Need for BAS
        2. Gradle overview
        3. Installation and quick start
          1. Pre-requisites
          2. Gradle for Windows
          3. Gradle for Mac/Linux
          4. The Gradle JVM option
        4. Our first script
        5. Gradle command Line arguments
        6. The Gradle GUI
        7. Start up script
        8. Build life cycle
          1. Initialization
          2. Configuration
          3. Execution
        9. Cache management
          1. Cache location
          2. Change Cache location
          3. Cache features
            1. Reduce the traffic
            2. Dependency location
            3. Version integration
            4. Switching off remote checking
            5. Version conflicts
        10. Gradle with IDE
          1. Installing the Gradle plugin in Eclipse
          2. Working with the Gradle project in IDE
        11. Summary
      9. 2. Groovy Essentials for Gradle
        1. Overview
          1. Integration with Java
          2. Minimum code
          3. Simpler I/O operations
          4. Integration with Ant
          5. Builder classes
          6. Closure
        2. Groovy script for Hello World
        3. Data types
          1. String
            1. Dynamic typing in Groovy
        4. Classes, beans, and methods
        5. Control structures
          1. The if-else condition
          2. The switch statement
          3. Loops
        6. Collections
          1. Set
          2. List
          3. Map
          4. Range
        7. Closure
        8. Builder
        9. Summary
      10. 3. Managing Task
        1. Build script basics
        2. Task configuration
        3. Task execution
        4. Task dependency
        5. Task ordering
        6. Task operations
          1. Conditional execution
          2. Build optimization
          3. Task rules
        7. Gradle's in-built tasks
          1. The Copy Task
          2. The Rename Task
          3. The Zip task
        8. Custom tasks
          1. Using buildSrc
          2. The standalone task
        9. Summary
      11. 4. Plugin Management
        1. The script plugin
        2. The binary plugin
        3. Gradle's in-built plugins
          1. Build and Test plugins
          2. Code analysis plugins
          3. IDE plugins
        4. The Java plugin
          1. Conventions
          2. Configuration
        5. The custom plugin
          1. The build file
          2. The buildSrc directory
          3. The Standalone project
        6. Summary
      12. 5. Dependency Management
        1. Overview
        2. Dependency configurations
          1. Dependency types
          2. Repositories
          3. Repositories configuration
        3. Dependency resolution
          1. Transitive dependency
          2. Exclude transitiveness
          3. Selective exclude
          4. Version conflicts
          5. Dynamic dependency
        4. Customizing the dependency
          1. Download file other than JAR
          2. Dependency on files with classifiers
          3. Replacing transitive dependencies
          4. Custom configuration for dependency
          5. Dependency reports
            1. Dependency-specific details
        5. Publishing artifacts
          1. Default artifacts
          2. Custom artifacts
            1. Generate additional XML file along with your JAR file
            2. Generate an additional ZIP file along with your JAR file
          3. Custom configuration
          4. The maven-publish plugins
            1. Publishing to the local-hosted repository
            2. Custom POM
        6. Summary
      13. 6. Working with Gradle
        1. The War plugin
        2. The Scala plugin
        3. Logging
        4. File management
          1. Reading files
          2. Writing files
          3. Creating files/directories
          4. File operations
          5. Filter files
          6. Delete files and directories
          7. FileTree
        5. Property management
          1. ext closure
          2. gradle.properties
          3. The command line
          4. The Custom properties file
        6. Multi-project build
          1. The Multi-project structure
          2. The Multi-project execution
          3. Task execution
          4. The Flat hierarchy
          5. Interproject dependency
          6. Configuration-level dependency
          7. Task-level dependency
          8. Library dependency
          9. Partial builds
          10. buildDependents
          11. buildNeeded
        7. Testing with Gradle
          1. JUnit
            1. Test configuration
              1. maxParallelForks
              2. The forkEvery option
              3. ignoreFailures
              4. filter
          2. TestNG
            1. Execution based on group
            2. Execution based on the TestNG suite file
        8. Summary
      14. 7. Continuous Integration
        1. Jenkins walk-through
          1. Jenkins installation
          2. Jenkins configuration
          3. Create job
          4. Execute job
        2. Checkstyle and PMD plugins
        3. The Sonar Runner plugin
        4. TeamCity walk-through
        5. Summary
      15. 8. Migration
        1. Migration from Ant
          1. Importing Ant file
            1. Accessing properties
            2. Update Ant tasks
          2. Using AntBuilder API
          3. Rewriting to Gradle
            1. Configuration
        2. Migration from Maven
          1. Build filename and project properties
          2. Properties
          3. Dependency management
            1. Exclude transitive
          4. Plugin declaration
          5. Repository configuration
          6. Multi-module declaration
          7. Default values
          8. Gradle init Plugin
        3. Summary
      16. 9. Deployment
        1. Role of Gradle in deployment
        2. Docker overview
        3. Installing Docker
        4. Docker commands
          1. Help command
          2. Download image
          3. The list of images
          4. Creating a container
          5. The container list
          6. Start/stop container
          7. Connecting to a container
          8. Deleting a container
          9. Removing an image
          10. Copying files to the container
          11. Container details
          12. Updating DNS settings
          13. Creating an image from a container
        5. Running an application in Docker
        6. Build, Deployment, and Test pipeline
        7. Summary
      17. 10. Building Android Applications with Gradle
        1. Creating Android project using Android Studio
        2. Building the Android project with Gradle
          1. buildTypes
            1. ProGuard settings
            2. Build flavors
          2. Running the application on a device/emulator
            1. Signing the release version
        3. Summary
      18. Index