Gradle Essentials
eBook - ePub

Gradle Essentials

Kunal Dabir, Abhinandan

Share book
  1. 176 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Gradle Essentials

Kunal Dabir, Abhinandan

Book details
Book preview
Table of contents
Citations

About This Book

Master the fundamentals of Gradle using real-world projects with this quick and easy-to-read guide

About This Book

  • Write beautiful build scripts for various types of projects effortlessly
  • Become more productive by harnessing the power and elegance of the Gradle DSL
  • Learn how to use Gradle quickly and effectively with this step-by-step guide

Who This Book Is For

This book is for Java and other JVM-based language developers who want to use Gradle or are already using Gradle on their projects.

No prior knowledge of Gradle is required, but some familiarity with build-related terminologies and an understanding of the Java language would help.

What You Will Learn

  • Master the Gradle DSL by identifying the building blocks
  • Learn just enough Groovy for Gradle
  • Set up tests and reports for your projects to make them CI ready
  • Create library, stand-alone, and web projects
  • Craft multi-module projects quickly and efficiently
  • Migrate existing projects to a modern Gradle build
  • Extract common build logic into plugins
  • Write builds for languages like Java, Groovy, and Scala

In Detail

Gradle is an advanced and modern build automation tool. It inherits the best elements of the past generation of build tools, but it also differs and innovates to bring terseness, elegance, simplicity, and the flexibility to build.

Right from installing Gradle and writing your first build file to creating a fully-fledged multi-module project build, this book will guide you through its topics in a step-by-step fashion.

You will get your hands dirty with a simple Java project built with Gradle and go on to build web applications that are run with Jetty or Tomcat. We take a unique approach towards explaining the DSL using the Gradle API, which makes the DSL more accessible and intuitive.

All in all, this book is a concise guide to help you decipher the Gradle build files, covering the essential topics that are most useful in real-world projects. With every chapter, you will learn a new topic and be able to readily implement your build files.

Style and approach

This step-by-step guide focuses on being productive with every chapter. When required, topics are explained in-depth to give you a good foundation of the Gradle fundamentals. The book covers most aspects of builds required for conventional JVM-based projects, and when necessary, points you towards the right resources.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Gradle Essentials an online PDF/ePUB?
Yes, you can access Gradle Essentials by Kunal Dabir, Abhinandan in PDF and/or ePUB format, as well as other popular books in Informatica & Programmazione open source. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781783982363

Gradle Essentials


Table of Contents

Gradle Essentials
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Running Your First Gradle Task
Installing Gradle
Installing manually
Installing on Mac OS X and Linux
Installing on Windows
Alternate methods of installing Gradle
Installing via OS-specific package managers
Mac OS X
Linux (Ubuntu)
Windows
Installing via SDKMAN
Verifying the installation
Setting JVM options
The Gradle command-line interface
The first Gradle build script
Task name abbreviation
Gradle Daemon
Gradle Wrapper
Generating wrapper files
Running a build via wrapper
Summary
2. Building Java Projects
Building a simple Java project
Creating a build file
Adding source files
Building the project
A brief introduction to plugins
Unit testing
Adding a unit test source
Adding the JUnit to the classpath
Running the test
Viewing test reports
Fitting tests in the workflow
Bundling an application distributable
Running the application with Gradle
Building the distribution archive
Generating IDE project files
Summary
3. Building a Web Application
Building a simple Java web project
Creating source files
Creating a build file
Building the artifact
Running the web application
Plugins to the rescue
References
Project dependencies
External libraries
The dynamic version
Transitive dependencies
Dependency configurations
Repositories
Summary
4. Demystifying Build Scripts
Groovy for Gradle build scripts
Why Groovy?
Groovy primer
Running Groovy code
Variables
Strings
Regular expressions
Closures
Data structures
List
Set
Map
Methods
Calling methods
Default values of parameters
Methods with map parameters/named parameters
Methods with varags
Methods with closure params
Classes
Constructors
Properties
Instance methods
Another look at applying plugins
Gradle – an object-oriented build tool
Build phases
Initialization
Configuration
Execution
Life cycle callbacks
Gradle Project API
Project methods
Project properties
Extra properties on a project
Tasks
Attaching actions to a task
Task flow control
dependsOn
finalizedBy
onlyIf
mustRunAfter and shouldRunAfter
Creating tasks dynamically
Setting default tasks
Task types
Using task types
Creating task types
References
Groovy
Gradle API and DSL used in this chapter
Summary
5. Multiprojects Build
The multiproject directory layout
The settings.gradle file
Organizing build logic in multiproject builds
Applying a build logic to all projects
Applying build logic to subprojects
Dependency on subprojects
Summary
6. The Real-world Project with Gradle
Migrating from an Ant-based project
Importing an Ant file
Using AntBuilder API
Rewriting Ant tasks to Gradle tasks
Migrating from a Maven project
Publishing artifacts
Continuous Integration
Generating documentation
Summary
7. Testing and Reporting with Gradle
Testing with TestNG
Integration testing
Code coverage
Code analysis reports
Summary
8. Organizing Build Logic and Plugins
Extracting build logic to buildSrc
The first plugin
Configuring plugins
Summary
9. Polyglot Projects
The polyglot application
Building Groovy projects
Building Scala projects
Joint compilation
References
Summary
Index

Gradle Essentials

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2015
Production reference: 1161215
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-236-3
www.packtpub.com

Credits

Authors
Kunal Dabir
Abhinandan
Reviewers
Eric Berry
André Burgaud
MichaƂ Huniewicz
Fredrik Sandell
Commissioning Editor
Amarabha Banerjee
Acquisition Editors
Richard Brookes-Bland
Larissa Pinto
Content Development Editor
Rashmi Suvarna
Technical Editor
Madhunikita Sunil Chindarkar
Copy Editor
Trishya Hajare
Project Coordinator
Izzat Contractor
Proofreader
Safis Editing
Indexer
Hemangini Bari
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade

About the Authors

Kunal Dabir has over 10 years of experience working with clients ranging from Fortune 500 companies to startups. Currently, he works as a Lead Consultant at ThoughtWorks. He is a Java user group's co-organizer and speaks at various meet-ups and conferences.
While he is always eager to learn a new language, he usually codes in languages such as Groovy, Scala, JavaScript, CoffeeScript, Ruby, and Java. He frequently cont...

Table of contents