1
votes

Update I am flagging this question to be closed as there seems to be no solution - the plugin is simply not behaving as it should and no-one seems to know why. I have ended up writing a small program to manually replicate the desired behaviour of the release plugin myself, using other plugins such as scm and versions. If you would like information on how I did this feel free to email me.


I have recently moved my project to maven. However, I am having issues with the release process.

My release procedure is as follows:

mvn scm:checkout -DconnectionUrl=scm:svn:https://my-server/svn/my-project/trunk -DcheckoutDirectory=my-project
cd my-project
mvn --batch-mode release:prepare
mvn release:perform

I start on 1.0.0-SNAPSHOT, I run the release procedure shown above. This updates my repo to the following (in ascending order of newness):

1.0.0-SNAPSHOT
1.0.0
1.0.1-SNAPSHOT

Everything occurs as expected, including the pom.xml updated to point to 1.0.1-SNAPSHOT and a tag called my-project-1.0.0 created in my SCM. However, when I run the procedure again, the following appears in my repo:

1.0.0-SNAPSHOT
1.0.1-SNAPSHOT
1.0.0
1.0.2-SNAPSHOT

That is, release 1.0.1 is never created, and instead 1.0.1-SNAPSHOT is released to 1.0.0. Note that every other aspect runs as expected - the pom.xml now points to 1.0.2-SNAPSHOT and a tag is created in my SCM with the name my-project-1.0.1.

In fact, every time I run the release procedure, the SNAPSHOT increases but the release is written to 1.0.0 with a new release never created. For example, re-running the release procedure 3 further times results in the following:

1.0.0-SNAPSHOT
1.0.1-SNAPSHOT
1.0.2-SNAPSHOT
1.0.3-SNAPSHOT
1.0.4-SNAPSHOT
1.0.0
1.0.5-SNAPSHOT

The expected behaviour for the above is:

1.0.0-SNAPSHOT
1.0.0
1.0.1-SNAPSHOT
1.0.1
1.0.2-SNAPSHOT
1.0.2
1.0.3-SNAPSHOT
1.0.3
1.0.4-SNAPSHOT
1.0.4
1.0.5-SNAPSHOT

The pom.xml for the very first version is shown below:

<project xmlns="http://maven.apache.org/POM/4.0.0" x mlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>my-project</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>my-project</name>

<distributionManagement>
    <repository>
        <id>my-server</id>
        <url>file://\\my-server\repo\</url>
    </repository>
</distributionManagement>

<scm>
    <developerConnection>scm:svn:https://my-server/svn/my-project</developerConnection>
</scm>

<build>
    <plugins>

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

    </plugins>


</build>

<repositories>
    <repository>
        <id>my-server</id>
        <url>file://\\my-server\repo\</url>
    </repository>
</repositories>

</project>

One of the answers below suggests I should create a separate release and snapshot repo, which I have not. Could this be causing the issue?

Note that I am using Jenkins to automatically invoke mvn deploy whenever code is committed. However this is acting exactly as expected (i.e. deploying whichever version is specified in the committed pom.xml to the repo) so I doubt this is part of the problem.

Many thanks for any assistance.


Update

Examining the output from the mvn release:perform command I see the following:

Checking out the project to perform the release ...
Executing: cmd.exe /X /C "svn --non-interactive checkout https://my-server/svn/my-project/tags/my-project-1.0.2 c:\localrelease\mvn\my-project\target\checkout"
Working directory: c:\localrelease\mvn\my-project\target
Invoking perform goals in directory c:\localrelease\mvn\my-project\target\checkout\tags\my-project-1.0.0\trunk
Executing goals 'deploy'...

And there is the reason it is releasing to 1.0.0 every time - it checks out the updated tag, but releases on the old 1.0.0 tag (even though the 1.0.1 tag IS present in the target/checkout folder). Why is it doing this?


Update 2

I have split to 2 separate repositories (one for snapshot and one for target) and this issue still occurs.

Also, something I have noticed upon investigating log for release:perform further: The checkout for tag my-project-1.0.1 contains the tag for 1.0.0. Similarly, the checkout for tag 1.0.2 contains the tags 1.0.0 and 1.0.1, etc. Is this correct behaviour?

Perhaps the release process is always looking in the tags folder of whatever it checks out and uses the first one it finds, which will always be 1.0.0 for every releases except the first release.

This seems like a very strange explanation but it is the only one I have so far for the behaviour I see. The question now is, what have I configured in my pom.xml incorrectly to cause this to happen?

Another note: when performing the release the deploy goal complains that 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-xxxx-plugin is missing. for maven-javadoc-plugin, maven-deploy-plugin and maven-source-plugin. Do I need to explicitly add these?

2

2 Answers

4
votes

The first things is that you are starting with the wrong version:

  1. checks out the latest code (with the latest pom currently pointing to 1.0.0)
  2. creates a new version 1.0.1-SNAPSHOT
  3. updates the pom to point to 1.0.1-SNAPSHOT and commits it

The usual way is to start with a SNAPSHOT version (also the first development steps), cause SNAPSHOT indicates it's under development on a way to a release.

  1. checkout latest code with version 1.0.0-SNAPSHOT
  2. will create a tag 1.0.0 in SVN and create new pom's (maven-release-prepare describes the detailed steps).
  3. creates a new version 1.0.1-SNAPSHOT

afterwards the release:perform will do the following:

checkout the tagged version 1.0.0 and will deploy site-deploy (maven-release-perform)

And the next call of the release cycle will go from 1.0.1-SNAPSHOT to 1.0.1 release and 1.0.2-SNAPSHOT for next development cycle.

Apart from the above you should use a repository manager like Artifactory, Nexus, Archiva instead of a file repository. In case if a RepoMgmt you have a separate repository for SNAPSHOT's and for releases which give the possibility to clean up the SNAPSHOT repository from time to time. You can also make a setup with file access which should be done in the correct way like the following:

<distributionManagement>
    <repository>
      <id>releases</id>
      <url>file:///C:/maven/releases</url>
    </repository>
    <snapshotRepository>
      <id>snapshots</id>
      <url>file:///C:/maven/snapshots</url>
    </snapshotRepository>
    <site>
      <id>site</id>
      <url>file:///C:/maven/sites/${project.groupId}/${project.artifactId}/${project.version}</url>
    </site>
</distributionManagement>

Furthermore if you make separate SNAPSHOT and release repository the metadata file will be looking different in release repository and SNAPSHOT repository.

The default release cycle is going from SNAPSHOT over a release to next SNAPSHOT like this:

1. Cycle
1.0.2-SNAPSHOT
1.0.2
1.0.3-SNAPSHOT

2. Cycle
1.0.3-SNAPSHOT
1.0.3
1.0.4-SNAPSHOT

3. Cycle
1.0.4-SNAPSHOT
1.0.4
1.0.5-SNAPSHOT

and so forth.
0
votes

I had the exact same problem and it turned out that the problem was SCM connection and developerConnection configuration. I've been using the standard SVN layout (tunk, branches, tags), but I've provided the URL for the root catalog of my repo:

<scm>
    <connection>scm:svn:file:///C:/var/svn/main</connection>
    <developerConnection>scm:svn:file:///C:/var/svn/main</developerConnection>
</scm>

instead, I should have provide the URL for trunk

<scm>
    <connection>scm:svn:file:///C:/var/svn/main/trunk</connection>
    <developerConnection>scm:svn:file:///C:/var/svn/main/trunk</developerConnection>
</scm>

That's all. Adding /trunk caused maven-release-plugin to publish my modules according to the current project.version.