Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list the Maven build/compilation sequence based on dependencies?

Tags:

maven

pom.xml

If I have a pom hierarchy in which the superpom calls multiple submodules which depend on one another, how can I list the build/compilation sequence based on dependencies? IOW, if the superpom has modules mod1, mod2, and mod3 and mod2 depends on mod3 and mod3 depends on mod1, then the sequence is mod1, mod3, then mod2. How can I list that order without complex XML parsing of data hierarchies from pom?

like image 825
amphibient Avatar asked Jan 16 '14 18:01

amphibient


People also ask

What is the sequence in which Maven build looks for the dependencies?

Maven searches for the dependencies in the following order: Local repository then Central repository then Remote repository. If dependency is not found in these repositories, maven stops processing and throws an error.

What is a Maven compile dependency?

Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects. provided. This is much like compile , but indicates you expect the JDK or a container to provide the dependency at runtime.

What are the three builds in the Maven life cycle?

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's web site.

What is groupId in Maven?

groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org. apache. maven.


3 Answers

What you want to know is the so called reactor build order.

The reactor determines the correct build order from the dependencies stated by each project in their respective project descriptors, and will then execute a stated set of goals. It can be used for both building projects and other goals, such as site generation. (Source: old multi-module documentation)

It collects all modules to build, sorts the projects and builds them in order. It guarantees that any module is build, before it is required by other modules.

As far as I know, there is no direct way of creating only a list of these items, but the closest thing to just get the information is:

mvn validate

It will show your reactor build order on top:

~/parent$ mvn validate
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] simple.parent
[INFO] simple.child
[INFO] simple.anotherchild
[...]                                                                        

No additional work is performed, besides validating the project for correctness and that all necessary information is available.

For more information, see also the guide to working with multiple modules and this answer about what the maven reactor is.

like image 90
Behe Avatar answered Oct 11 '22 17:10

Behe


Perhaps you're looking for the Maven dependency:tree option? You'll probably have to adjust the includes to include only your modules. http://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html

mvn dependency:tree -Dverbose -DoutputFile=tree.txt -DoutputType=text -Dincludes=com.mycompany.*
like image 8
brokethebuildagain Avatar answered Oct 11 '22 17:10

brokethebuildagain


Improved version of @rhinoceros.xn:

mvn validate > validate.log

project_name=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.name -q -DforceStdout)

sed '1,/^\[INFO\] Reactor Build Order:/ d' validate.log | awk '/\[INFO\] -+</ {exit} {print}' | awk '{ print $2 }' | awk \!/^"$project_name"$/ | awk 'NF'
like image 1
happy_marmoset Avatar answered Oct 11 '22 19:10

happy_marmoset