Skip to content

How to create releases with Maven

dstenger edited this page Jul 31, 2019 · 6 revisions

This manual applies to all CITE projects using Maven.

How to configure Maven

Configure Maven release plugin

Following is a recommended Maven release plugin configuration for all projects:

      <plugin>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.5.3</version>
        <configuration>
          <autoVersionSubmodules>true</autoVersionSubmodules>
          <tagNameFormat>@{project.version}</tagNameFormat>
          <releaseProfiles>release</releaseProfiles>
        </configuration>
      </plugin>

Create signed artefacts

Add maven-gpg-plugin to pom.xml of project to be deployed:

  <profiles>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>1.6</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
                <configuration>
                  <!-- Enable if GPG 2.1+ is used -->
                  <!--<gpgArguments>
                    <arg>&#45;&#45;pinentry-mode</arg>
                    <arg>loopback</arg>
                  </gpgArguments>-->
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

Deploy artefacts to staging repository

Add staging repository to pom.xml of project to be deployed:

  <distributionManagement>
    <repository>
      <id>sonatype-nexus-staging</id>
      <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
  </distributionManagement>

Configure Maven scm publish plugin

Following is a recommended Maven configuration for all projects:

...
      <plugin>
        <artifactId>maven-scm-publish-plugin</artifactId>
        <version>1.1</version>
        <configuration>
          <scmBranch>gh-pages</scmBranch>
        </configuration>
      </plugin>
...
  <distributionManagement>
    <site>
      <id>site</id>
      <url>[SCM_URL]</url>
    </site>
  </distributionManagement>
...

[SCM_URL] has to be replaced with the URL of the project repository (e.g. scm:git:git@github.com:opengeospatial/ets-gpkg12.git)

How to create Jenkinsfile

Create Jenkinsfile with path jenkinsfiles/release/Jenkinsfile and add following content.

pipeline {
  agent any
  tools {
    maven 'mvn'
    jdk 'JDK 8'
  }
  stages {
    stage('Preparation') {
      steps{
        deleteDir()
        sh 'git clone git@github.com:opengeospatial/[TEST_SUITE_ID].git .'
      }
    }
    stage('Release') {
      steps{
        sh 'mvn --version'
        sh 'mvn -Dresume=false -DdryRun=true release:prepare -Psign-artifacts-with-ogc,integration-tests,docker -DreleaseVersion=${releaseVersion} -DdevelopmentVersion=${developmentVersion}'
        sh 'mvn -Dresume=false release:prepare release:perform -Psign-artifacts-with-ogc,integration-tests,docker -DreleaseVersion=${releaseVersion} -DdevelopmentVersion=${developmentVersion}'
      }
    }
    stage('Publication of site') {
      steps{
        sh 'mvn --version'
        sh 'git checkout ${releaseVersion}'
        sh 'mvn clean install site site:stage scm-publish:publish-scm'
      }
    }
    stage('Results') {
      steps{
        archive 'target/*'
      }
    }
  }
}

Caution: All place holders ([...]) must be replaced.

Now, releases can be created with any Jenkins instance by using the Jenkinsfile.

How to execute Maven plugins manually

Create release with Maven release plugin

Execute followings commands to create a release:

mvn -Dresume=false -DdryRun=true release:prepare
mvn -Dresume=false release:prepare release:perform -Psign-artifacts-with-ogc

Publish sites with Maven scm publish plugin

Execute following commands to publish sites:

mvn clean install site site:stage scm-publish:publish-scm

If a release shall be deployed, check out the tag of the release first.

You can’t perform that action at this time.