Gist: Maven/ Invalidate Dependency Cache

With Maven, we can achieve the similar effect of invalidating local dependency cache and download artifacts from repository by using following command.

mvn -U
Advertisements

Maven: Updating Artefact Version in a Multi-Module Project

Using following Maven command, the version of artifacts can be updated in a multi-module maven project.

mvn versions:set -DnewVersion='new-version'

For instance, the following maven command updates the version in POM.xml files of the enclosed moduels to 7.1.0-DEV-SNAPSHOT.

mvn versions:set -DnewVersion='7.1.0-DEV-SNAPSHOT'

Note that, by default this command creates a backup of the existing POM files. In essence, it creates a pom.xml.versionBackup for each POM file. This behavior can be disabled as follows.

mvn versions:set -DnewVersion='7.1.0-DEV-SNAPSHOT' -DgenerateBackupPoms=false

Maven Commands for Building Specific Modules

In my job, we work with a maven multi-module project. While using maven, I have discovered several commands that are quite effective during development. In this post, and in the upcoming posts I am planning to share those.

So, today's post is regarding Maven command to build a specific project. For instance, we have a project, with three modules: A, B, and C, where C depends on B and B depends on A. And we are working with B at this moment. Using following command, we can run different maven phases on module B as follows.

mvn -pl :B clean install 

We can include multiple projects as follows :A, :B.

What is more interesting is that the following command run maven command not only this module, but also the modules that depends on it.

mvn -pl :B clean install -amd 

The above command in effect includes module C.

Using –am command, we can include all the dependencies as well, which is module A in this example.

Hope this helps!