Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EE4J Maven Publishing"

Line 1: Line 1:
 
To publish Maven artifacts and release them, you need to use the nexus-staging-maven-plugin.
 
To publish Maven artifacts and release them, you need to use the nexus-staging-maven-plugin.
Configure it in your pom.xml by adding the following under <pluginManagement>:
+
The plugin has been configured in the ee4j parent pom, starting with version 1.0.5.
 +
Make sure you're using at least that version:
  
 
<pre>
 
<pre>
                <plugin>
+
    <parent>
                    <groupId>org.sonatype.plugins</groupId>
+
        <groupId>org.eclipse.ee4j</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
+
        <artifactId>project</artifactId>
                    <extensions>true</extensions>
+
        <version>1.0.5</version>
                    <configuration>
+
    </parent>
                        <serverId>ossrh</serverId>
+
                        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+
                    </configuration>
+
                </plugin>
+
 
</pre>
 
</pre>
  
(It sure would be convenient if that were in the parent pom.)
+
The configuration in the parent pom causes the Maven deploy operation to be done
 +
using the nexus-staging-maven-plugin instead.
  
Add the following to whatever profile you use when releasing artifacts:
+
I created a job to do the build and deploy to staging for JAF.
 +
The same approach should work for most simple projects.
  
<pre>
 
                    <plugin>
 
                        <groupId>org.apache.maven.plugins</groupId>
 
                        <artifactId>maven-gpg-plugin</artifactId>
 
                        <version>1.6</version>
 
                    </plugin>
 
                    <plugin>
 
                        <groupId>org.apache.maven.plugins</groupId>
 
                        <artifactId>maven-deploy-plugin</artifactId>
 
                        <configuration>
 
                          <!-- To prefer nexus-staging-maven-plugin -->
 
                          <skip>true</skip>
 
                        </configuration>
 
                  </plugin>
 
                  <plugin>
 
                        <groupId>org.sonatype.plugins</groupId>
 
                        <artifactId>nexus-staging-maven-plugin</artifactId>
 
                        <extensions>true</extensions>
 
                        <executions>
 
                            <execution>
 
                                <id>default-deploy</id>
 
                                <phase>deploy</phase>
 
                                <goals>
 
                                    <goal>deploy</goal>
 
                                </goals>
 
                            </execution>
 
                        </executions>
 
                        <configuration>
 
                            <serverId>ossrh</serverId>
 
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
 
                            <autoReleaseAfterClose>false</autoReleaseAfterClose>
 
                        </configuration>
 
                    </plugin>
 
</pre>
 
 
I created a job to do the build and deploy to staging for JAF.
 
 
Create a freestyle job using the [[EE4J Build|usual setup]] with all the required
 
Create a freestyle job using the [[EE4J Build|usual setup]] with all the required
 
configuration and security injection.  Here's the script I use for
 
configuration and security injection.  Here's the script I use for
Line 62: Line 25:
 
the use of the maven-release-plugin, [https://github.com/eclipse-ee4j/jsonp/wiki/JSONP-release-job as others have explained].
 
the use of the maven-release-plugin, [https://github.com/eclipse-ee4j/jsonp/wiki/JSONP-release-job as others have explained].
 
The key parts of this script are the use of the nexus-staging-maven-plugin
 
The key parts of this script are the use of the nexus-staging-maven-plugin
to create a staging repository, deploy to that repository, and close it.
+
to clean up any existing staging repositories to allow this job to be run
(Note that three STAGING_* variables need to be customized for each project.)
+
multiple times to redeploy the artifacts.
 +
 
 +
Note that I have deploy-snapshot and deploy-release profiles in my pom,
 +
largely for historical reasons.  Change or remove those as appropriate.
 +
You will need to customize the Maven build and deploy commands for
 +
your project.
  
 
<pre>
 
<pre>
Line 73: Line 41:
  
 
HELP_PLUGIN='org.apache.maven.plugins:maven-help-plugin:2.1.1'
 
HELP_PLUGIN='org.apache.maven.plugins:maven-help-plugin:2.1.1'
 
# Customize these for each project
 
STAGING_NAME=jakartaactivation
 
STAGING_DESC="Eclipse Project for JAF"
 
STAGING_PROFILE_ID=70fc011e3d589e
 
 
 
  
 
# Workaround: GPG initialization
 
# Workaround: GPG initialization
Line 88: Line 49:
 
done
 
done
  
# XXX - just to make sure it doesn't change
+
mvnq() {
mvn -B nexus-staging:rc-list-profiles
+
    # filter out progress reports (-B) and download details
 +
    mvn -B "$@" | grep -v '^\[INFO\] Download'
 +
}
  
# Clean up from any previous failures
 
for id in $(mvn -B nexus-staging:rc-list | \
 
  egrep "^\[INFO\] ${STAGING_NAME}\-[0-9]+[ ]+OPEN[ ]+${STAGING_DESC}" | \
 
  awk '{print $2}')
 
do
 
    echo "Closing and dropping $id"
 
    mvn -B nexus-staging:rc-close nexus-staging:rc-drop \
 
      -DstagingRepositoryId="$id" \
 
      -DstagingDescription="${STAGING_DESC}"
 
done
 
 
# Open a new staging repo
 
mvn -B nexus-staging:rc-open \
 
  -DstagingProfileId="${STAGING_PROFILE_ID}" \
 
  -DstagingDescription="${STAGING_DESC}"
 
 
# Get the ID of the newly created staging repo
 
STAGING_REPO_ID=$(mvn -B nexus-staging:rc-list | \
 
  egrep "^\[INFO\] ${STAGING_NAME}\-[0-9]+[ ]+OPEN[ ]+${STAGING_DESC}" | \
 
  awk '{print $2}' | head -1)
 
  
 +
#
 
# Build
 
# Build
mvn -B clean install
+
#
 +
# Since we depend on other staged artifacts, need to use -Pstaging
 +
# when building and deploying.
 +
#
 +
mvnq -Pstaging clean install
  
# Deploy
+
#
# Select the appropriate profile from our pom based on whether
+
# If we're deploying a SNAPSHOT release, it's easy.
# we're deploying a SNAPSHOT release or not.
+
#
 
VERSION=$(mvn -B ${HELP_PLUGIN}:evaluate \
 
VERSION=$(mvn -B ${HELP_PLUGIN}:evaluate \
 
           -Dexpression=project.version 2> /dev/null | grep -v INFO)
 
           -Dexpression=project.version 2> /dev/null | grep -v INFO)
 
case "$VERSION" in
 
case "$VERSION" in
 
*-SNAPSHOT)
 
*-SNAPSHOT)
     PROFILE=deploy-snapshot
+
     mvnq -Pstaging -Pdeploy-snapshot deploy
     ;;
+
     exit
*)
+
    PROFILE=deploy-release
+
 
     ;;
 
     ;;
 
esac
 
esac
mvn -B -Poss-release -P"${PROFILE}" \
 
  -DstagingRepositoryId="${STAGING_REPO_ID}" deploy
 
  
# Close the nexus staging repository
+
#
mvn -B nexus-staging:rc-close \
+
# Clean up from any previous failures
  -DstagingRepositoryId="${STAGING_REPO_ID}" \
+
# List all the profiles, then for each profile,
  -DstagingDescription="${STAGING_DESC}"
+
# list all the repositories and drop them.
 +
#
 +
for name in $(mvnq nexus-staging:rc-list-profiles | \
 +
    grep -v 'Central Bundles' | \
 +
    awk '$3 == "BOTH" {print $4}')
 +
do
 +
    name=${name//./}    # squash out all the dots
 +
    for id in $(mvnq nexus-staging:rc-list | \
 +
        awk '$1 ~ /\[INFO\]/ && $2 ~ /^'"${name}"'\-[0-9]+$/ {print $2}')
 +
    do
 +
        echo "Dropping $id"
 +
        mvnq -DstagingRepositoryId="$id" nexus-staging:rc-drop
 +
    done
 +
done
  
# If it's a SNAPSHOT version, just release it.
+
 
case "$VERSION" in
+
#
*-SNAPSHOT)
+
# Deploy
    mvn -B nexus-staging:rc-release \
+
#
      -DstagingRepositoryId="${STAGING_REPO_ID}" \
+
mvnq -Poss-release -Pstaging -Pdeploy-release deploy
      -DstagingDescription="${STAGING_DESC}"
+
    ;;
+
esac
+
 
</pre>
 
</pre>
  
Line 149: Line 103:
 
the deployed artifacts can be tested, and a Release Review can be started.
 
the deployed artifacts can be tested, and a Release Review can be started.
 
Once the testing is complete and the Release Review is approved, a job with
 
Once the testing is complete and the Release Review is approved, a job with
the following script is used to actually release the staged artifacts:
+
the following script is used to actually release the staged artifacts.
 +
This script should not need to be customized per project.
 +
(Note that I have not tested this script yet.)
  
 
<pre>
 
<pre>
Line 158: Line 114:
 
PATH="${MVN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
 
PATH="${MVN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  
 
+
#
# Customize these for each project
+
# List all the profiles, then for each profile,
STAGING_NAME=jakartaactivation
+
# list all the repositories and release them.
STAGING_DESC="Eclipse Project for JAF"
+
# XXX - Assumes we want to release everything that's currently staged.
#STAGING_PROFILE_ID=70fc011e3d589e
+
#
 
+
for name in $(mvnq nexus-staging:rc-list-profiles | \
 
+
    grep -v 'Central Bundles' | \
# Get the ID of the staging repo
+
    awk '$3 == "BOTH" {print $4}')
STAGING_REPO_ID=$(mvn -B nexus-staging:rc-list | \
+
do
  egrep "^\[INFO\] ${STAGING_NAME}\-[0-9]+[ ]+OPEN[ ]+${STAGING_DESC}" | \
+
    name=${name//./}    # squash out all the dots
  awk '{print $2}' | head -1)
+
    for id in $(mvnq nexus-staging:rc-list | \
 
+
        awk '$1 ~ /\[INFO\]/ && $2 ~ /^'"${name}"'\-[0-9]+$/ {print $2}')
# Release it.
+
    do
mvn -B nexus-staging:rc-release \
+
        echo "Dropping $id"
  -DstagingRepositoryId="${STAGING_REPO_ID}" \
+
        mvnq -DstagingRepositoryId="$id" nexus-staging:rc-release
  -DstagingDescription="${STAGING_DESC}"
+
    done
 +
done
 
</pre>
 
</pre>
  
 
[[Category:Jakarta_EE]]
 
[[Category:Jakarta_EE]]

Revision as of 14:59, 20 November 2018

To publish Maven artifacts and release them, you need to use the nexus-staging-maven-plugin. The plugin has been configured in the ee4j parent pom, starting with version 1.0.5. Make sure you're using at least that version:

    <parent>
        <groupId>org.eclipse.ee4j</groupId>
        <artifactId>project</artifactId>
        <version>1.0.5</version>
    </parent>

The configuration in the parent pom causes the Maven deploy operation to be done using the nexus-staging-maven-plugin instead.

I created a job to do the build and deploy to staging for JAF. The same approach should work for most simple projects.

Create a freestyle job using the usual setup with all the required configuration and security injection. Here's the script I use for the job. It can be used to build and deploy either a SNAPSHOT release or a final release. Note that it depends on the version number already having been updated if you want to deploy a final release. You could replace the simple use of "mvn deploy" with the use of the maven-release-plugin, as others have explained. The key parts of this script are the use of the nexus-staging-maven-plugin to clean up any existing staging repositories to allow this job to be run multiple times to redeploy the artifacts.

Note that I have deploy-snapshot and deploy-release profiles in my pom, largely for historical reasons. Change or remove those as appropriate. You will need to customize the Maven build and deploy commands for your project.

TOOLS_PREFIX='/opt/tools'
JAVA_PREFIX="${TOOLS_PREFIX}/java/oracle"
MVN_HOME="${TOOLS_PREFIX}/apache-maven/latest"
JAVA_HOME="${JAVA_PREFIX}/jdk-8/latest"
PATH="${MVN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

HELP_PLUGIN='org.apache.maven.plugins:maven-help-plugin:2.1.1'

# Workaround: GPG initialization
gpg --batch --import ${KEYRING}
for fpr in $(gpg --list-keys --with-colons  | awk -F: '/fpr:/ {print $10}' | sort -u);
do
  echo -e "5\ny\n" |  gpg --batch --command-fd 0 --expert --edit-key $fpr trust;
done

mvnq() {
    # filter out progress reports (-B) and download details
    mvn -B "$@" | grep -v '^\[INFO\] Download'
}


#
# Build
#
# Since we depend on other staged artifacts, need to use -Pstaging
# when building and deploying.
#
mvnq -Pstaging clean install

#
# If we're deploying a SNAPSHOT release, it's easy.
#
VERSION=$(mvn -B ${HELP_PLUGIN}:evaluate \
           -Dexpression=project.version 2> /dev/null | grep -v INFO)
case "$VERSION" in
*-SNAPSHOT)
    mvnq -Pstaging -Pdeploy-snapshot deploy
    exit
    ;;
esac

#
# Clean up from any previous failures
# List all the profiles, then for each profile,
# list all the repositories and drop them.
#
for name in $(mvnq nexus-staging:rc-list-profiles | \
    grep -v 'Central Bundles' | \
    awk '$3 == "BOTH" {print $4}')
do
    name=${name//./}    # squash out all the dots
    for id in $(mvnq nexus-staging:rc-list | \
        awk '$1 ~ /\[INFO\]/ && $2 ~ /^'"${name}"'\-[0-9]+$/ {print $2}')
    do
        echo "Dropping $id"
        mvnq -DstagingRepositoryId="$id" nexus-staging:rc-drop
    done
done


#
# Deploy
#
mvnq -Poss-release -Pstaging -Pdeploy-release deploy

When the above job is used to deploy a final release to a staging repository, the deployed artifacts can be tested, and a Release Review can be started. Once the testing is complete and the Release Review is approved, a job with the following script is used to actually release the staged artifacts. This script should not need to be customized per project. (Note that I have not tested this script yet.)

TOOLS_PREFIX='/opt/tools'
JAVA_PREFIX="${TOOLS_PREFIX}/java/oracle"
MVN_HOME="${TOOLS_PREFIX}/apache-maven/latest"
JAVA_HOME="${JAVA_PREFIX}/jdk-8/latest"
PATH="${MVN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

#
# List all the profiles, then for each profile,
# list all the repositories and release them.
# XXX - Assumes we want to release everything that's currently staged.
#
for name in $(mvnq nexus-staging:rc-list-profiles | \
    grep -v 'Central Bundles' | \
    awk '$3 == "BOTH" {print $4}')
do
    name=${name//./}    # squash out all the dots
    for id in $(mvnq nexus-staging:rc-list | \
        awk '$1 ~ /\[INFO\]/ && $2 ~ /^'"${name}"'\-[0-9]+$/ {print $2}')
    do
        echo "Dropping $id"
        mvnq -DstagingRepositoryId="$id" nexus-staging:rc-release
    done
done

Back to the top