javamavenbitbucket-pipelines

Maven prepare and perform - should it create a new branch?


I am using Maven 3.9 and am writing our CICD bitbucket pipelines.

The script executes these commands:

mvn -B release:prepare 
mvn -B release:perform

This updates the project-version in the pom.xml and creates a git tag. e.g. git tag

notification-service-0.0.1
notification-service-0.0.2
notification-service-0.0.3

pom.xml

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.0</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.nexct</groupId>
<artifactId>notification-service</artifactId>
<version>0.0.4-SNAPSHOT</version>
<name>notification-service</name>
<description>Notification Service</description>
<properties>
    <java.version>21</java.version>
</properties>

...

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
                <pushChanges>false</pushChanges>
            </configuration>
        </plugin>
    </plugins>

<scm>
    <connection>scm:git:ssh://git@bitbucket.org/xxxx/notification-service.git</connection>
    <developerConnection>scm:git:ssh://git@bitbucket.org/xxxx/notification-service.git</developerConnection>
    <url>ssh://git@bitbucket.org/xxxx/notification-service</url>
    <tag>HEAD</tag>
</scm>

Question

Should this also be creating a branch too?

The reason I ask, is the mvn -B release:perform gets the following error, because the branch does not exist:

fatal: Remote branch notification-service-0.0.3 not found in upstream origin

I thought it would commit the updated code to the existing branch, e.g. main branch, not the notification-service-0.0.3 branch. Or is it supposed to create a new branch for each release?

We have been using a generic branch called release, but perhaps our git flow model is incorrect?


Solution

  • The maven-release-plugin does not create a branch. What you see is that it's missing the tag that it creates usually, and that is maybe because you didn't push that to the origin.

    I would recommend that you remove the <pushChanges>false</pushChanges> for now until you have a working release, and then start fine-tuning that step-by-step.

    You can do this locally first, the maven-release-plugin even supports dry-runs, but with them you will not be able to simulate the whole process. At one point you will have to include the real build and the real repository stuff. Still you can do the release completely local first, and start putting it into your CI system after local release works.

    If you don't have any steps between prepare and perform, you could even execute mvn -B release:prepare release:perform in one go.