Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ subprojects {
// But since the dependsOn is within the conditional, the dependency is not created for release versions
// so the publish in that case is never executed.
if (version.toString().endsWith('SNAPSHOT')) {
dependsOn tasks.publish
exec {
workingDir project.projectDir
commandLine 'bash', "${project.rootDir}/scripts/snapshot_management.sh", project.name, project.version
}
}
doFirst {
if (!version.toString().endsWith('SNAPSHOT')) {
Expand Down
41 changes: 41 additions & 0 deletions scripts/snapshot_management.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# This script manages the uploading of snapshots to the Maven Central snapshot repository, and deletion of the associated snapshots after a set retention time.
set -e

subproject=$1
version=$2

echo "Running $(basename $0) for subproject \"$subproject\" and version \"$version\""
echo "Executing in directory = $(pwd)"

zipfile=${subproject}.${version}.zip

pushd build/local-repo
zip -qr ${zipfile} *

bearer_token=$(echo "$MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME:$MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD" | base64)

# We delete older snapshots before uploading the newest one to the project's snapshot repository on Maven Central.
for deployments in $subproject; do
Comment thread
cswilson252 marked this conversation as resolved.
getId=$(curl -s --request POST \
--header "Authorization: Bearer ${bearer_token}" \
'https://central.sonatype.com/api/v1/publisher/deployments/files')
staleId=$(getId | jq -r '.deploymentIds')
echo "id from old snapshot: $staleId"

dropStale=$(curl --request DELETE \
--verbose \
--header "Authorization: Bearer ${bearer_token}" \
"https://central.sonatype.com/api/v1/publisher/deployments/{$staleId}")
done

# We publish to the snapshot repository automatically whenever this script is called, without manual intervention.
answer=$(curl --request POST \
--verbose \
--header "Authorization: Bearer ${bearer_token}" \
--form bundle="@${zipfile}" \
'https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC')

echo "curl request answer: $answer"

popd
Loading