Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
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. | ||
− | + | 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> | ||
− | + | <parent> | |
− | + | <groupId>org.eclipse.ee4j</groupId> | |
− | + | <artifactId>project</artifactId> | |
− | + | <version>1.0.5</version> | |
− | + | </parent> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</pre> | </pre> | ||
− | + | 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 [[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 | + | 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. | ||
<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' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
# Workaround: GPG initialization | # Workaround: GPG initialization | ||
Line 88: | Line 49: | ||
done | done | ||
− | # | + | mvnq() { |
− | mvn -B | + | # filter out progress reports (-B) and download details |
+ | mvn -B "$@" | grep -v '^\[INFO\] Download' | ||
+ | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | # | ||
# Build | # 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. | |
− | # we're deploying a SNAPSHOT release | + | # |
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) | ||
− | + | mvnq -Pstaging -Pdeploy-snapshot deploy | |
− | + | exit | |
− | + | ||
− | + | ||
;; | ;; | ||
esac | 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 | |
− | + | ||
− | + | ||
− | + | ||
</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" | ||
− | + | # | |
− | # | + | # 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 | ||
</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