Maven - How to Update the Parent POM File

Problem:

When a maven project contains one or multiple parent POM files which update the argLine of the Surefire or the Failsafe plugin, you will need to update the parent POM file as well as the project POM.

Solution:

2 flags need to be added to the -pom command:

  1. modifyParentPom true - Enable the feature

  2. mavenLocalRepoPath /path/to/m2/repository - Provide the path of the .m2 folder’s repository

There are 3 different scenarios:

  1. If the project POM file has a relativePath in the <parent> section - it will update this file

  2. If no relativePath, it will search for a pom.xml file in the parent folder and update this file

  3. If no pom.xml file in the parent folder, it will search for it in the .m2 repository folder (under the ../repository/<groupId>/<artifactId>/<version>/<artifactId>-<versionId>.pom)

Example:

java -jar sl-build-scanner.jar -pom -configfile slmaven.json -workspacepath . -mavenLocalRepoPath /Users/Tests/.m2/repository -modifyParentPom true