diff --git a/build.gradle b/build.gradle index ab4b16a146..2f86927075 100644 --- a/build.gradle +++ b/build.gradle @@ -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')) { diff --git a/scripts/snapshot_management.sh b/scripts/snapshot_management.sh new file mode 100644 index 0000000000..ea3ce95c75 --- /dev/null +++ b/scripts/snapshot_management.sh @@ -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 +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