mavennullpointerexceptionreleasemaven-release-pluginversions-maven-plugin

Maven versions-maven-plugin versions plugin 2.2 -- Maven Uncle Situation


Maven is 3.1.0.

I'm using versions-maven-plugin:2.2 in my project's pom.xml (as shown below). Apart from the usual pom.xml file configuration, I'm just showing the main code snapshot below:

<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>

    <artifactId>tools-parent</artifactId>
    <version>0.0.7-SNAPSHOT</version>
    <packaging>pom</packaging>

    <description>
        Infrastructure related to the &quot;vapp&quot; and
        &quot;deployer&quot; utilities.
    </description>

    <parent>
        <groupId>com.company.product</groupId>
        <artifactId>deploy-parent</artifactId>
        <version>0.0.6-SNAPSHOT</version>
    </parent>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.9.4</version>
                <configuration>
                    <connectionType>connection</connectionType>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <!-- Make sure that only non-snapshot versions are used for the dependencies. Only active when property 'snapshotDependencyAllowed' is false. -->
                        <id>enforce-no-snapshots</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <skip>${snapshotDependencyAllowed}</skip>
                            <rules>
                                <requireReleaseDeps>
                                    <message>No Snapshots Allowed!</message>
                                </requireReleaseDeps>
                                <requireReleaseVersion>
                                    <message>No Snapshots Allowed!</message>
                                </requireReleaseVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Now, when I run: mvn clean install, it builds successfully.

NOTE: In my project, I have a parent section, where I'm dependent upon deploy-parent artifact whose group id "com.company.product" is the same group id what I want to tools-parent artifact (whose pom.xml I have pasted above) but deploy-parent is an artifact of another repository/project.

When I run: mvn versions:set -DnewVersion=0.0.7, I get the following error message.

[INFO] ------------------------------------------------------------------------
[INFO] Building tools-parent 0.0.7-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:set (default-cli) @ tools-parent ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /user/home/u100123/giga/tools
[INFO] Processing change of com.company.product:tools-parent:0.0.7-SNAPSHOT -> 0.0.7
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] tools-parent .................................... FAILURE [1.093s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.404s
[INFO] Finished at: Fri May 01 20:44:22 GMT-00:00 2015
[INFO] Final Memory: 12M/246M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.2:set (default-cli) on project tools-parent: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.2:set failed. NullPointerException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

NOW, when I change the versions-maven-plugin version back to 2.1 (which what I was using earlier), the above mvn versions:set -DnewVersion=0.0.7 command is working successfully and pom.xml file is successfully getting changed to <version>0.0.7</version> for tools-parent artifact.

With version 2.2, it's giving me the error and not changing the version to 0.0.7.

  1. Any reasons why 2.2 is failing? What can be done to resolve it?

Solution

  • It seems like some bug.

    Solution:

    1. I have to add <groupId>com.company.product</groupId> property outside of ... section as well i.e. for tools-parent, NOW version-maven-plugin:2.2 is working fine i.e. I added the top line (as shown below). The only thing is, what's the use of parent section then (apart from inheriting the main code of what deploy-parent is brining to tools-parent project). Why groupId needs to be defined output of parent section for artifactId tools-parent when it's already there in the parent section for versions-maven-plugin:2.2 to work successfully.

    The most important thing is: This issue occurs only in case your pom.xml for a project/module has a <parent> section where the parent section's artifactId is not the parent of the project itself (a typical - Maven Uncle situation) i.e. if tools-parent artifact is defined in the parent section of another module (lets say tools-child) then version 2.2 will work successfully. But if tools-child's parent section is not containing the artifactId as "tools-parent" and is something else for ex: deploy-parent/some-different-project-artifact (which resides in a different project in your source control tool) then, for tools-child artifactId, we need groupId value also set outside of the parent section as well (even if the groupId of parent section's artifactId is same/different to tools-child's groupId).

    <groupId>com.company.product</groupId>
    <artifactId>tools-parent</artifactId>
    <version>0.0.7-SNAPSHOT</version>
    <packaging>pom</packaging>
    
    <description>
        Infrastructure related to the &quot;vapp&quot; and
        &quot;deployer&quot; utilities.
    </description>
    
    <parent>
        <groupId>com.company.product</groupId>
        <artifactId>deploy-parent</artifactId>
        <version>0.0.6-SNAPSHOT</version>
    </parent>
    

    --OR

    2. Switch back to versions-maven-plugin:2.1