Chapter 5. Dependency Management

One of the most important features of any software is managing dependencies. As we know, no software works in isolation and we usually depend on third-party or open source libraries. The libraries are required during the compile and runtime execution and they have to be available in the classpath. Gradle has excellent support for dependency management. We just need to write few lines of code in the build file and Gradle internally does all the heavy lifting of managing configurations.

In this chapter, we will go into details of dependency management of Gradle. We will discuss the different features such as how to manage project dependencies, resolving conflicts, and resolution strategies. We will also discuss how to publish artifacts in different repositories.

Overview

Dependency management is one of the most the important features of any build tool. It helps to manage software dependencies in a better way. If you are using Ant, which initially did not support any dependency management, you need to write the name of each and every dependent jar file and its location to build.xml. For small applications that do not have many dependencies, this approach might work well. However, for enterprise applications, where software depends on hundreds of other libraries, which internally can depend on some other libraries (transitive dependencies), this approach of configuring each and every jar file in your build.xml could work but it requires huge effort to maintain it. Also, managing their version conflicts would be really a big pain for any developer and could turn the build process into a nightmare. To resolve these drawbacks in Ant, Maven came with an internal dependency management solution.

Later, Ant also integrated with Apache Ivy (a dependency management solution) to provide the same feature. Gradle came with its own dependency management implementation. It helps to define first-level dependencies, logically group them into different configurations, define multiple repositories and also provide tasks to publish assets after the execution of the build file. It also supports Ivy, Maven, and flat file repositories. In this chapter, along with dependency management, we will also look into repositories configurations and asset publications, that is, how to configure different repositories and upload assets to repositories.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.59.198