Gradle Dependency Management
()
About this ebook
- Be in total control of your dependencies
- Deploy your artifacts to repositories with Gradle
- Learn through code snippets and real-life examples
If you work on Java projects, use Gradle as a build automation tool, and you use dependencies in your project, this is the book for you. Additionally, if you want to deploy your project artifacts as dependencies for other developers using Gradle, you've found the right book.
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.
Read more from Hubert Klein Ikkink
Gradle Effective Implementation Guide Rating: 3 out of 5 stars3/5Gradle Effective Implementations Guide - Second Edition Rating: 0 out of 5 stars0 ratings
Related to Gradle Dependency Management
Related ebooks
Administrating Solr Rating: 0 out of 5 stars0 ratingsMeteor Design Patterns Rating: 0 out of 5 stars0 ratingsJava 8 to 21: Explore and work with the cutting-edge features of Java 21 (English Edition) Rating: 0 out of 5 stars0 ratingsJasmine JavaScript Testing - Second Edition Rating: 0 out of 5 stars0 ratingsOpenCart Theme and Module Development Rating: 0 out of 5 stars0 ratingsComputer Vision for the Web Rating: 0 out of 5 stars0 ratingsGo Programming Cookbook: Over 75+ recipes to program microservices, networking, database and APIs using Golang Rating: 0 out of 5 stars0 ratingsCloud Development and Deployment with CloudBees Rating: 0 out of 5 stars0 ratingsInstant Play Framework Starter Rating: 0 out of 5 stars0 ratingsLo-Dash Essentials Rating: 0 out of 5 stars0 ratingsAngularJS Deployment Essentials Rating: 0 out of 5 stars0 ratingsInstant StyleCop Code Analysis How-to Rating: 0 out of 5 stars0 ratingsOpa Application Development Rating: 0 out of 5 stars0 ratingsExtending Jenkins Rating: 0 out of 5 stars0 ratingsBuilding Web Applications with Python and Neo4j Rating: 0 out of 5 stars0 ratingsSymfony2 Essentials Rating: 0 out of 5 stars0 ratingsMastering Gradle Rating: 0 out of 5 stars0 ratingsPHP 5 CMS Framework Development - 2nd Edition Rating: 0 out of 5 stars0 ratingsXamarin Mobile Application Development for Android - Second Edition Rating: 0 out of 5 stars0 ratingsLearning Concurrent Programming in Scala Rating: 0 out of 5 stars0 ratingsPHPEclipse: A User Guide Rating: 3 out of 5 stars3/5jQuery Game Development Essentials Rating: 0 out of 5 stars0 ratingsApache Cassandra Essentials Rating: 4 out of 5 stars4/5The Secrets of Roblox Brookhaven 2022 Rating: 0 out of 5 stars0 ratingsEmber.js in Action Rating: 0 out of 5 stars0 ratingsLibgdx Cross-platform Game Development Cookbook Rating: 0 out of 5 stars0 ratingsMastering Android NDK Rating: 0 out of 5 stars0 ratingsPractical XMPP Rating: 0 out of 5 stars0 ratingsAjax Bible Rating: 3 out of 5 stars3/5
Internet & Web For You
Podcasting For Dummies Rating: 4 out of 5 stars4/5More Porn - Faster!: 50 Tips & Tools for Faster and More Efficient Porn Browsing Rating: 3 out of 5 stars3/5The Mega Box: The Ultimate Guide to the Best Free Resources on the Internet Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Cybersecurity For Dummies Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5The Logo Brainstorm Book: A Comprehensive Guide for Exploring Design Directions Rating: 4 out of 5 stars4/5The Designer's Web Handbook: What You Need to Know to Create for the Web Rating: 0 out of 5 stars0 ratingsThe $1,000,000 Web Designer Guide: A Practical Guide for Wealth and Freedom as an Online Freelancer Rating: 5 out of 5 stars5/5Six Figure Blogging Blueprint Rating: 5 out of 5 stars5/5Coding For Dummies Rating: 5 out of 5 stars5/5The Digital Marketing Handbook: A Step-By-Step Guide to Creating Websites That Sell Rating: 5 out of 5 stars5/5Wireless Hacking 101 Rating: 4 out of 5 stars4/5Tor and the Dark Art of Anonymity Rating: 5 out of 5 stars5/5Stop Asking Questions: How to Lead High-Impact Interviews and Learn Anything from Anyone Rating: 5 out of 5 stars5/5Surveillance and Surveillance Detection: A CIA Insider's Guide Rating: 0 out of 5 stars0 ratings200+ Ways to Protect Your Privacy: Simple Ways to Prevent Hacks and Protect Your Privacy--On and Offline Rating: 0 out of 5 stars0 ratingsThe Beginner's Affiliate Marketing Blueprint Rating: 4 out of 5 stars4/5How To Make Money Blogging: How I Replaced My Day-Job With My Blog and How You Can Start A Blog Today Rating: 4 out of 5 stars4/5Six Figure Blogging In 3 Months Rating: 4 out of 5 stars4/5Hacking : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Ethical Hacking Rating: 5 out of 5 stars5/5How To Start A Podcast Rating: 4 out of 5 stars4/5Wordpress for Beginners: The Easy Step-by-Step Guide to Creating a Website with WordPress Rating: 5 out of 5 stars5/5Mike Meyers' CompTIA Security+ Certification Guide, Third Edition (Exam SY0-601) Rating: 5 out of 5 stars5/5How To Start A Profitable Authority Blog In Under One Hour Rating: 5 out of 5 stars5/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsEverybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5
Reviews for Gradle Dependency Management
0 ratings0 reviews
Book preview
Gradle Dependency Management - Hubert Klein Ikkink
Table of Contents
Gradle Dependency Management
Credits
About the Author
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
Downloading the color images of this book
Errata
Piracy
Questions
1. Defining Dependencies
Declaring dependency configurations
Declaring dependencies
External module dependencies
Defining client module dependencies
Using project dependencies
Defining file dependencies
Using internal Gradle and Groovy dependencies
Using dynamic versions
Getting information about dependencies
Accessing dependencies
Buildscript dependencies
Optional Ant task dependencies
Managing dependencies
Summary
2. Working with Repositories
Declaring repositories
Using the Maven JCenter repository
Using the Maven Central repository
Using the Maven local repository
Using Maven repositories
Using the flat directory repository
Using Ivy repositories
Using different protocols
Summary
3. Resolving Dependencies
Understanding dependency resolution
Configuring transitive dependencies
Disabling transitive dependencies
Excluding transitive dependencies
Using artifact-only dependencies
Resolving version conflicts
Using the newest version
Failing on version conflict
Forcing a version
Customizing dependency resolution rules
Using client modules
Using dynamic versions and changing modules
Understanding the dependency cache
Command-line options for caching
Changing cache expiration
Summary
4. Publishing Artifacts
Defining artifact configurations
Defining artifacts
Using the archive task
Using artifact files
Creating artifacts
Publishing artifacts to the local directory
Excluding the descriptor file
Signing artifacts
Using configurations to sign
Using archive tasks to sign
Summary
5. Publishing to a Maven Repository
Defining publication
Defining publication artifacts
Using archive task artifacts
Using file artifacts
Using software components
Generating POM files
Customizing the POM file
Defining repositories
Publishing to the local Maven repository
Publishing to the Maven repository
Publishing to Artifactory
Publishing to Nexus
Summary
6. Publishing to Bintray
What is Bintray?
Defining a new repository
Defining the Bintray plugin
Deploying publications to Bintray
Configuring the Bintray plugin
Summary
7. Publishing to an Ivy Repository
Defining publications
Defining publication artifacts
Using archive task artifacts
Using file artifacts
Using software components
Generating Ivy descriptor files
Customizing the descriptor file
Defining repositories
Publishing to a local directory
Publishing to Artifactory
Publishing to Nexus
Summary
Index
Gradle Dependency Management
Gradle Dependency Management
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 author, 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: June 2015
Production reference: 1120615
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-278-9
www.packtpub.com
Credits
Author
Hubert Klein Ikkink
Reviewers
Tony Dieppa
Izzet Mustafaiev
Konstantin Zgirovskiy
Commissioning Editor
Pramila Balan
Acquisition Editor
Sonali Vernekar
Content Development Editor
Athira Laji
Technical Editor
Siddhesh Ghadi
Copy Editor
Sarang Chari
Project Coordinator
Harshal Ved
Proofreader
Safis Editing
Indexer
Monica Mehta
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
About the Author
Hubert Klein Ikkink, born in 1973, lives in Tilburg, the Netherlands, with his beautiful wife and three 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 Tilburg University. After finishing his studies in 1996, he started to develop Java software. Over the years, his focus switched from applets to servlets, and from Java Enterprise Edition applications to Spring-based software and Groovy-related technologies. He likes the expressiveness of the Groovy language and how it is used in other tools, such as Gradle. He also wrote Gradle Effective Implementation Guide, Packt Publishing.
In the Netherlands, Hubert works for a company called JDriven. JDriven focuses on technologies that simplify and improve the 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.
About the Reviewers
Izzet Mustafaiev is a family guy who likes to throw BBQ parties and travel.
Professionally, he is a software engineer working at EPAM Systems with primary skills in Java and hands-on experience in Groovy/Ruby, and is exploring FP with Erlang/Elixir. Izzet has participated in different projects as a developer and as an architect. He advocates XP, clean code, and DevOps practices when he speaks at engineering conferences.
Konstantin Zgirovskiy grew up alongside Android, in a manner of speaking. In 2008, he started programming web services and Chrome extensions for an online browser game, which was later made official. In 2011, Konstantin continued to explore Android through writing a game, which brought him victory in a local programming contest. Nowadays, he works at Looksery, Inc., where he is involved in developing an app with face-tracking and transformation technology for video chats, video selfies, and images on mobile devices.
I would like to thank my cats, friends, colleagues, and family for their support. My thanks also go to Packt Publishing for this opportunity. Additionally, I would like to thank Dasha Tsareva-Lenskaya for motivating and encouraging me whenever I got distracted.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com, and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Preface
When we write code in our Java or Groovy project, we mostly have dependencies on other projects or libraries. For example, we could use the Spring framework in our project, so we are dependent on classes found in the Spring framework. We want to be able to manage such dependencies from Gradle, our build automation tool.
We will see how we can define and customize the dependencies we need. We learn not only how to define the dependencies, but also how to work with repositories that store the dependencies. Next, we will see how to customize the way Gradle resolves dependencies.
Besides being dependent on other libraries, our project can also be a dependency for other projects. This means that we need to know how to deploy our project artifacts so that other developers can use it. We learn how to define artifacts and how to deploy them to, for example, a Maven or Ivy repository.
What this book covers
Chapter 1, Defining Dependencies, introduces dependency configurations as a way to organize dependencies. You will learn about the different types of dependencies in Gradle.
Chapter 2, Working with Repositories, covers how we can define repositories that store our dependencies. We will see not only how to set the location, but also the layout of a repository.
Chapter 3, Resolving Dependencies, is about how Gradle resolves our dependencies. You will learn how to customize the dependency resolution and resolve conflicts between dependencies.
Chapter 4, Publishing Artifacts, covers how to define artifacts for our project to be published as dependencies for others. We will see how to use configurations to define artifacts. We also use a local directory as a repository to publish the artifacts.
Chapter 5, Publishing to a Maven Repository, looks at how to publish our artifacts to a Maven repository. You will learn how to define a publication for a Maven-like repository, such as Artifactory or Nexus, and how to use the new and incubating publishing feature of Gradle.
Chapter 6, Publishing to Bintray, covers how to deploy our artifacts to Bintray. Bintray calls itself a Distribution as a Service and provides a low-level way to publish our artifacts to the world. In this chapter, we will look at how to use the Bintray Gradle plugin to publish our artifacts.
Chapter 7, Publishing to an Ivy Repository, is about publishing our artifacts to an Ivy repository. We will look into the different options to publish our artifacts to an Ivy repository, which is actually quite similar to publishing to a Maven repository.
What you need for this book
In order to work with Gradle and the code samples in this book, we need at least Java Development Kit (version 1.6 or higher), Gradle (samples are written with Gradle 2.3), and a good text editor.
Who this book is for
This book is for you if you are working on Java or Groovy projects and are using, or are going to use, Gradle to build your code. If your code depends on other projects or libraries, you will learn how to define and customize those dependencies. Your code can also be used by other projects, so you want to publish your project as a dependency for others whom you want to read this book.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: We can include other contexts through the use of the include directive.
A block of code is set as follows:
// Define new configurations for build.
configurations {
// Define configuration vehicles.