Pages

Monday, January 20, 2020

Building components separately in maven (Advanced Reactor)


Multi-module Project:
 
find out the available modules in pom.xml using maven dependency plugin :
 
$ mvn --also-make dependency:tree | grep maven-dependency-plugin | awk '{ print $(NF-1) }'

command will list down the all the sub-modules are available in the project.
it only gets the artifactId, from the root (or parent) module.

If you want the directories :

$ mvn -q --also-make exec:exec -Dexec.executable="pwd"

Starting with the Maven 2.1 release, there are new Maven command line options which allow you to manipulate the way that Maven will build multi-module projects. These new options are:

-rf, --resume-from
        Resume reactor from specified project

-pl, --projects
        Build specified reactor projects instead of all projects

-am, --also-make
        If project list is specified, also build projects required by the list

-amd, --also-make-dependents
        If project list is specified, also build projects that depend on projects on the list


Resuming Builds:

The -rf or --resume-from option can come in handy if you want to tell the Maven Reactor to resume a build from a particular project. This can be useful if you are working with a large multimodule project and you want to restart a build at a particular project in the Reactor without running through all of the projects that precede it in the build order.

$ mvn --resume-from sample-client-connector install

Specifying a Subset of Projects:
The -pl or --projects option allows you to select a list of projects from a multimodule project. This option can be useful if you are working on a specific set of projects, and you'd rather not wait through a full build of a multi-module project during a development cycle. If you only wanted Maven to build the sample-rest and sample-client-connector project, you would use the following syntax from the sample-parent/ directory:

$ mvn --projects sample-client-connector,sample-rest install

Making a Subset of Projects:
If you wanted to run a portion of the larger build, you would use the -pl or --projects option with the -am or --also-make option. When you specify a project with the -am option, Maven will build all of the projects that the specified project depends upon (either directly or indirectly). Maven will examine the list of projects and walk down the dependency tree, finding all of the projects that it needs to build.

$ mvn --projects sample-services --also-make install

Making Dependent Projects:
 While the -am command makes all of the projects required by a particular project in a multi-module build, the -amd or --also-make-dependents option configures Maven to build a project and any project that depends on that project. When using --also-make-dependents, Maven will examine all of the projects in our reactor to find projects that depend on a particular project. It will automatically build those projects and nothing else.

$ mvn --projects sample-services --also-make-dependents install

Resuming a "make" Build

Combining --project, --also-make, and --resume-from provides you with the ability to refine your build even further.

$ mvn --projects sample-webapp --also-make \
      --resume-from sample-services install

No comments:

Post a Comment