You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Currently there is no automated process for releasing from Artifactory to Maven-Central so we need to use a custom script (the JFrog CLI currently doesn't support the required endpoints).

This script assumes you have already pushed from Artifactory (or whatever your artifact store is), to Bintray, the package has been requested and included in JCenter, and that it has not already been synced to Maven Central.

If your package has not been included in JCenter yet, follow this guide from JFrog (Note: You'll need to used the 'Old' UI in order to see the options detailed in that guide. See this StackOverflow post for directions on how to get to the Old UI).


bintray to jcenter/ maven central sync script
#!/bin/bash

# Requirements:
#  - curl
#  - jq
#  - jfrog : configured with credentials https://www.jfrog.com/confluence/display/CLI/JFrog+CLI

# i.e. odpi-lf
BINTRAY_USER=$username
BINTRAY_TOKEN="ABCDEFG12345"
# i.e. odpi
JFROG_ORG=$organization
# i.e. egeria
JFROG_PROJECT=$project
# i.e. 1.3
VERSION=$release_version
# i.e. org.odpi.egeria
MVN_PROJECT=$mvn-id
MVN_QUERY="https://search.maven.org/solrsearch/select?q=g:%22${MVN_PROJECT}%22%20AND%20v:${VERSION}&wt=json&rows=1000000"
# Artifactory release repository
# i.e. https://odpi.jfrog.io/odpi
RT_URL=$url
RT_TOKEN=$bearer-token
RT_REPO=${project}-release

if [ ${BINTRAY_TOKEN} == "" || ${RT_TOKEN} == "" ]; then
    exit 1
fi

function config_rt () {
	jfrog rt c --interactive=false --url ${RT_URL} --access-token ${RT_TOKEN} ${JFROG_ORG}
}

function list_rt_packages () {
	jfrog rt search ${RT_REPO}/*${VERSION}* | jq '.[] | .path' | cut -d/ -f5 | sort | uniq | tee packages_${VERSION}
}

function list_mvn_packages () {
	curl -L ${MVN_QUERY} | jq '.response.docs[] | .a' | sort | uniq | tr -d '"' | tee mvn_packages_${VERSION}
}

function diff_packages_to_sync () {
	diff -u0 packages_${VERSION} mvn_packages_${VERSION} | grep '^-' | grep -v '\-\-\-' | cut -c2- | tee packages_to_sync_${VERSION}
}

function sync_packages () {
    if [ ! -f packages_to_sync_${VERSION} ]; then
        echo "packages_to_sync_${VERSION} file missing"
        exit 1
    fi
    while read -r package_name; do
        sync_package $package_name ${VERSION} ;
    done < packages_to_sync_${VERSION}
}

# Needs package name, version
function sync_package () {
    local package_name=$1
    local package_version=$2
    echo "Syncing ${package_name}:${package_version}"
    curl \
    -u ${BINTRAY_USER}:${BINTRAY_TOKEN} \
    -H "Content-Type: application/json" \
    -X POST \
    -d '{"close":"1"}' \
    -L "https://api.bintray.com/maven_central_sync/${JFROG_ORG}/${JFROG_PROJECT}/${package_name}/versions/${package_version}"
    echo
}

config_rt
list_rt_packages
list_mvn_packages
diff_packages_to_sync
sync_packages

Step-by-step guide

The script above needs some environment variables set and then can be run in a screen session (expect 1-2 minutes per package), to sync from Bintray to JCenter and Maven Central.

  1. You need to create a Bintray account and create a support ticket to be added to your respective organization.
  2. Once there, you'll need an API key on Bintray (Profile → API Key)
  3. Fill out the environment variables and then run the script to sync.




  • No labels