pom-editor-maven-plugin
pom-editor-maven-plugin copied to clipboard
[New Goal Proposal]: add-mdep to add or update dependencies into the `dependencyManagement` XML tag
What is the purpose of the new goal?
Today, the add-dep add or update dependencies into the default profile, which means, into the project/dependencies XML node.
Many projects are managing their dependencies by using the project/dependencyManagement/dependencies XML nodes and then they're declaring the dependencies at project/dependencies XML nodes as needed.
Let's create a new goal called add-mdep to add or update managed dependencies to the project/dependencyManagement/dependencies XML node.
What is the expected behavior and output of the new goal?
Goal syntax:
$ mvn pom-editor:add-mdep -Dgav=<DEPENDENCY COORDINATES> -Dscope=<SCOPE> -Dtype=<TYPE> -Dclassifier=<CLASSIFIER>
New inputs:
| Property | Description |
|---|---|
| gav | define the dependency to be add/update following the pattern groupId:artifactId:version |
| scope | define the scope for the given dependency. Default value is compile. Must follow the default Maven Dependency Scope |
| type | define the dependency type. Default value is jar |
| classifier | define the dependency classifier. Default value is empty |
:warning: Warning
This execution causes a side-effect into the target POM, then the backup process must keeping working.
Expected behavior and outcomes:
Scenario 01:
- Given the necessity to add or update a given dependency into a given POM without the
dependencyManagement/dependenciesXML node defined
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.arrudalabs</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
- When the
add-mdepgoal is executed with a given dependency
$ mvn pom-editor:add-mdep -Dgav='a:a:1.0'
- Then the
add-mdepgoal should add or update the given dependency into theproject/dependencyManagement/dependenciesXML node from the target profile;
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.arrudalabs</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>a</groupId>
<artifactId>a</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Scenario 02:
- Given the necessity to add or update a given dependency into a given POM with the
dependencyManagement/dependenciesXML node defined already
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.arrudalabs</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>b</groupId>
<artifactId>b</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
- When the
add-mdepgoal is executed with a given dependency
$ mvn pom-editor:add-mdep -Dgav='a:a:1.3'
- Then the
add-mdepgoal should add or update the given dependency into theproject/dependencyManagement/dependenciesXML node from the target profile;
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.arrudalabs</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency> <!-- added dependency-->
<groupId>a</groupId>
<artifactId>a</artifactId>
<version>1.3</version>.
</dependency>
<dependency>
<groupId>b</groupId>
<artifactId>b</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>