Book Image

Apache Maven Dependency Management

By : Jonathan LALOU
Book Image

Apache Maven Dependency Management

By: Jonathan LALOU

Overview of this book

<p>Managing dependencies in a multi-module project is difficult. In a multi-module project, libraries need to share transitive relations with each other. Maven eliminates this need by reading the project files of dependencies to figure out their inter-relations and other related information. Gaining an understanding of project dependencies will allow you to fully utilize Maven and use it to your advantage.</p> <p>Aiming to give you a clear understanding of Maven’s functionality, this book focuses on specific case studies that shed light on highly useful Maven features which are often disregarded. The content of this book will help you to replace homebrew processes with more automated solutions.</p> <p>This practical guide focuses on the variety of problems and issues which occur during the conception and development phase, with the aim of making dependency management as effortless and painless as possible. Throughout the course of this book, you will learn how to migrate from non-Maven projects to Maven, learn Maven best practices, and how to simplify the management of multiple projects. The book emphasizes the importance of projects as well as identifying and fixing potential conflicts before they become issues. The later sections of the book introduce you to the methods that you can use to increase your team’s productivity. This book is the perfect guide to help make you into a proud software craftsman.</p>
Table of Contents (14 chapters)

Scopes


In the previous chapter, we have seen the groupId, artifactId, and version tags, used to determine in a deterministic way a project.

The dependency tag owns another subtag named scope.

Nomenclature of scope

The scope hints at the visibility of a dependency, relatively to the different life phases (build, test, runtime, and so on). Maven provides six scopes: compile, provided, runtime, test, system, and import.

Let's review them a bit more.

Compile

This is the default scope. Dependencies with <scope>compile</scope> are needed to build, test, and run, and are propagated to dependent projects.

Scope compile is to be used in most of the cases, for instance, when a class of your src/ folder uses imports of classes.

So, as an example, consider that your code holds the following:

  import org.apache.log4j.Logger;
  import org.springframework.util.Assert;

If your code holds the preceding lines then, your pom.xml will contain the following:

     <dependencies>
          <dependency...