Configuration files for one or more Maven pom.xml?

I would like to ask these questions related to pom.xml files in Maven projects.

  • What is the reason for having multiple pom.xml for all dependency libraries instead of having all dependencies in one pom.xml ?
  • Where should these pom.xml files be pom.xml in the Maven project?

This is a pom.xml example for Spring framework - http://search.maven.org/remotecontent?filepath=org/springframework/spring-core/3.2.5.RELEASE/spring-core-3.2.5.RELEASE.pom

+6
source share
2 answers
  • What is the reason for having multiple pom.xml for all dependency libraries instead of having all dependencies in one pom.xml?

A maven project can be made from many artifacts. One artifact may be a string manipulation library. Another might be a webapp that uses this String manipulation library.

This is why you should not put all your dependencies in one pom: your string manipulation library should not have a link to servlets.jar just because the unbound pom is webapp. Each artifact should have only what it needs in its path to the classes.

(You may be interested in learning about the dependencyManagement tag, but it is not directly related to your question.)

  • Where should these pom.xml files be located in the Maven project?

Like @MariuszS related to Standard Directory Layout .

In the top-level files describing the project: the pom.xml file (and any properties, maven.xml or build.xml when using Ant). In addition, there are text documents designed so that the user can immediately read the receiver: README.txt, LICENSE.txt, etc.

+6
source

It depends on your project, if the project is small, and the product of this project (artifact) is only one, and one pom is enough. But if your project has a lot of artifacts (libraries, WARs, EAR, etc.), then pom is required for each artifact (usually).

The concept of Maven is that one project definition (POM) generates only one artifact (there are exceptions). Each project should have a separate directory with pom.xml inside and source directories, if necessary.

One maven project can create two different applications (e.g. desktop and webapp). These different applications have different dependencies.

Example structure of a multimodal project: https://github.com/peter-lawrey/Java-Chronicle

More details

+3
source

Source: https://habr.com/ru/post/958169/


All Articles