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 175: Line 175:
 
   -DstagingDescription="${STAGING_DESC}"
 
   -DstagingDescription="${STAGING_DESC}"
 
</pre>
 
</pre>
 +
 +
[[Category:Jakarta_EE]]

Revision as of 11:04, 31 October 2018

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>:

                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <extensions>true</extensions>
                    <configuration>
                        <serverId>ossrh</serverId>
                        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                    </configuration>
                </plugin>

(It sure would be convenient if that were in the parent pom.)

Add the following to whatever profile you use when releasing artifacts:

                    <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>

I created a job to do the build and deploy to staging for JAF. 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 create a staging repository, deploy to that repository, and close it. (Note that three STAGING_* variables need to be customized for each 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'

# Customize these for each project
STAGING_NAME=jakartaactivation
STAGING_DESC="Eclipse Project for JAF"
STAGING_PROFILE_ID=70fc011e3d589e



# 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

# XXX - just to make sure it doesn't change
mvn -B nexus-staging:rc-list-profiles

# 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
mvn -B clean install

# Deploy
# Select the appropriate profile from our pom based on whether
# we're deploying a SNAPSHOT release or not.
VERSION=$(mvn -B ${HELP_PLUGIN}:evaluate \
           -Dexpression=project.version 2> /dev/null | grep -v INFO)
case "$VERSION" in
*-SNAPSHOT)
    PROFILE=deploy-snapshot
    ;;
*)
    PROFILE=deploy-release
    ;;
esac
mvn -B -Poss-release -P"${PROFILE}" \
  -DstagingRepositoryId="${STAGING_REPO_ID}" deploy

# Close the nexus staging repository
mvn -B nexus-staging:rc-close \
  -DstagingRepositoryId="${STAGING_REPO_ID}" \
  -DstagingDescription="${STAGING_DESC}"

# If it's a SNAPSHOT version, just release it.
case "$VERSION" in
*-SNAPSHOT)
    mvn -B nexus-staging:rc-release \
      -DstagingRepositoryId="${STAGING_REPO_ID}" \
      -DstagingDescription="${STAGING_DESC}"
    ;;
esac

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:

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"


# Customize these for each project
STAGING_NAME=jakartaactivation
STAGING_DESC="Eclipse Project for JAF"
#STAGING_PROFILE_ID=70fc011e3d589e


# Get the ID of the 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)

# Release it.
mvn -B nexus-staging:rc-release \
  -DstagingRepositoryId="${STAGING_REPO_ID}" \
  -DstagingDescription="${STAGING_DESC}"

Back to the top