Skip to content

[New Goal Proposal]: add-mdep to add or update dependencies into the dependencyManagement XML tag #21

@dearrudam

Description

@dearrudam

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

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/dependencies XML 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-mdep goal is executed with a given dependency
$ mvn pom-editor:add-mdep -Dgav='a:a:1.0'
  • Then the add-mdep goal should add or update the given dependency into the project/dependencyManagement/dependencies XML 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/dependencies XML 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-mdep goal is executed with a given dependency
$ mvn pom-editor:add-mdep -Dgav='a:a:1.3'
  • Then the add-mdep goal should add or update the given dependency into the project/dependencyManagement/dependencies XML 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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is neededproposalIdea proposalquestionFurther information is requested

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions