How to prevent pushing SNAPSHOT version in maven-release-plugin?

I have a maven project with a lot of modules (and modules inside modules). I am using maven-release-plugin to control versioning in pom.xml files .

When running the command, the mvn release:prepare

plugin pushes two commits with the messages: "[maven-release-plugin] is preparing the release v0.9.0.38" and "[maven-release-plugin] is preparing for the next iteration of development . Here the second is just a snapshot version.

Here are the settings for the maven-release-plugin :

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>

            <configuration>
                <tagNameFormat>v@{project.version}</tagNameFormat>
                <autoVersionSubmodules>true</autoVersionSubmodules>
                <checkModificationExcludes>
                    <checkModificationExclude>pom.xml</checkModificationExclude>
                    <checkModificationExclude>*/pom.xml</checkModificationExclude>
                </checkModificationExcludes>
                <branchBase>master</branchBase>
            </configuration>
        </plugin>
    </plugins>
</build>

      

On push, I set the tag to a remote git project (you can see it in <tagNameFormat>v@{project.version}</tagNameFormat>

), so I need to push commits, but I don't want it to output the snapshot versions (like 0.9.0.38-SNAPESHOT).

Edit:

Problem:

As I am incrementing the minor version of the project on every commit by running mvn release:prepare

.
e.g. Commits look like this:

[maven-release-plugin] preparing for next development iteration
[maven-release-plugin] preparing v0.9.0.38 release
(refactoring) Code cleaned up
[maven-release-plugin] preparing for next development iteration
[maven-release-plugin] preparing release v0.9.0.37
(feature) Added I18N support

It looks very ugly, and pushing three commits for each change is a very bad solution just to simply increment a minor version of the pom file not by hand.

What I need?

  • Before each version of the project, increment the commit (including all modules)
  • And set the tag to the remote git repository.
  • And it should be done with a single commit with a custom message

How can I achieve this?

+3


source to share


2 answers


The described behavior is intended - the plugin will upgrade the version of your modules after they are released, which is normal. So the top tip is to think twice before setting it up.

If you are using the Git, you can set pushChanges on false

to avoid depression. After that you can undo the last commit and push changes

git reset HEAD~ --hard
git push origin master

      

The advice is more practical if you explain why you think the second commit is redundant.

You can also always use dryRun if you are not sure about the changes.



Update:

  • Make your changes
  • mvn versions:set -DnewVersion=<version-to-set> -DgenerateBackupPoms=false

  • git commit -m "your-comment"

  • git tag <your-tag>

  • Push commit / tag

These steps can be easily aggregated into a script file to avoid monkey work.

Alternatively, you can have a look at BuildNumber-maven-plugin , which might also be helpful.

+1


source


To just update versions, you can use release:update-versions

and then execute manually.



The documentation provides an option suppressCommitBeforeTag

for release:prepare

which sounds like it should prevent the commit.

0


source







All Articles