2

I'm using Maven 3.

I have multiple maven projects, namely: the 'data model', the 'service', and the 'presentation', split into 3 different projects. They are configured separately (ie. not using maven parent pom).

project setup

I have maven release plugin setup on my project correctly, such that when I run mvn release:clean release:prepare release:perform on each individual project, it updates the project version (ie: from 3.4.5-SNAPSHOT to 3.4.5) as well as all the other things.

The problem here is, 'presentation' is dependent on 'service' is dependent on 'data model', and I refer to the projects in the pom files with the version number.

While I develop, say for example I would refer to 'service' in 'presentation' as 3.4.5-SNAPSHOT. But during deploy, I have to release 'service' to change the version to 3.4.5, then I have to update my version reference of 'service' in 'presentation', before I can run a release on 'presentation'.

Is there an automated way of doing this such that I don't need to update the reference of dependent projects during release?

What I have so from thanks to below comments: Updated: 25/03/2013

Run maven with:

versions:use-releases -Dmessage="update from snapshot to release" scm:checkin release:clean release:prepare release:perform

Outcome: version updated, but release build failed.

1 Answer 1

4

The Versions Maven Plugin may help you to achieve requirement, especially the goal versions:use-releases. You may be interested in the goal versions:use-next-releases and versions:use-latest-releases as well.

Side Note:

Normally, the good practice is define them as a Maven Multiple Module( here and here). This allow us to manage the version easier as the following example.

The parent

<groupId>my-group</groupId>
<artifactId>my-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

    .....

<modules>
    <module>my-model</module>
    <module>my-service</module>
    <module>my-ui</module>
</modules>

The my-model

<parent>
    <groupId>my-group</groupId>
    <artifactId>my-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>my-model</artifactId>

The my-service

<parent>
    <groupId>my-group</groupId>
    <artifactId>my-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>my-service</artifactId>
<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>my-model</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencies>

The my-ui

<parent>
    <groupId>my-group</groupId>
    <artifactId>my-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>my-ui</artifactId>
<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>my-service</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencies>

Regarding to the above example when we release, the related version will be updated based on the parent version automatically.

5
  • versions:use-releases looks like just what I need. I'll get it setup and tested. let you know. =)
    – JackDev
    Mar 25, 2013 at 4:31
  • version:use-release removes 'SNAPSHOT' from the version, but as I'm running it using: "mvn version:use-release release:clean release:prepare release:perform", it gives me: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) on project [Presentation]: Cannot prepare the release because you have local modifications : [ERROR] [pom.xml.versionsBackup:unknown] [ERROR] [pom.xml:modified]
    – JackDev
    Mar 25, 2013 at 5:00
  • I'm afraid that you may need to commit the changes once before releasing. Since the versions:use-releases changes the pom.xml as it mentions about you have local modifications. Mar 25, 2013 at 5:07
  • Tried it with 'version.. scm:checkin ... release ...' just now but got the following error: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) on project [Presentation]: Cannot prepare the release because you have local modifications : [ERROR] [pom.xml.versionsBackup:unknown]. The ideal solution is to somehow automate it...
    – JackDev
    Mar 25, 2013 at 5:23
  • You may need to create a profile which contains org.apache.maven.plugins:maven-scm-plugin with phase:install and goal:checkin. together with the version:use-release. The solution may look like mvn -Pnew-profile release.... Mar 25, 2013 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.