Reputation: 966
Bintray seems to be a nice service and has many articles on how they are better than using Nexus, but for some reasons there are no migration scripts or tools to actually move artifacts from Nexus to Bintray. I'm looking for a solution for migrating a Nexus repository (either private or public) to Bintray without much hassle.
I'm aware that Bintray has REST API and it seems to be that you could just write a script that can create project versions and then upload artifacts from Nexus one by one, but for some reason I keep getting errors from this REST API and can't come with something that actually works.
Upvotes: 1
Views: 258
Reputation: 966
as @JBaruch already mentioned there is no tool to do that, so I had to write script which would do this. Script might be super flaky, slow and hard to maintain, so use with care. Also note that script is quite basic and you might be required to fix some stuff afterwards by hand.
# run inside of your nexus repo directory, like /opt/nexus/sonatype_work/my_maven_repository
BINTRAY_USER=""
BINTRAY_TOKEN=""
BINTRAY_API="https://api.bintray.com"
BINTRAY_REPO="your_org/maven"
for META_FILE in `find . -type f -name 'maven-metadata.xml' ! -path "*/.nexus/*" ! -path "*/.meta/*" ! -path "*/.index/*"`;
do
echo "Meta-file: $META_FILE"
PRODUCT_DIR=`dirname ${META_FILE#./}`
PRODUCT_ID=`basename $PRODUCT_DIR`
PACKAGE_DIR=`dirname $PRODUCT_DIR`
PACKAGE=`echo $PACKAGE_DIR | tr '/' '.'`
echo "Found product $PRODUCT_ID in $PACKAGE at path $PRODUCT_DIR"
# make project on bintray
PROJECT_ID="$PACKAGE:$PRODUCT_ID"
PROJ_TMPL='{
"name": "%s",
"desc": "%s",
"licenses": ["Apache-2.0"],
"vcs_url": "https://github.com/your_org/",
"public_download_numbers": false,
"public_stats": true
}'
PROJ_DEF=`printf "$PROJ_TMPL" $PROJECT_ID $PACKAGE.$PRODUCT_ID`
PROJ_URL="$BINTRAY_API/packages/$BINTRAY_REPO"
echo "Posting $PROJ_DEF to $PROJ_URL"
curl -H "Content-Type: application/json" -d "$PROJ_DEF" -u$BINTRAY_USER:$BINTRAY_TOKEN $PROJ_URL
echo ""
for VERSION_DIR in `find $PRODUCT_DIR/* -maxdepth 1 -type d ! -name . ! -name .. ! -name '.meta' ! -name '.index' ! -name '.nexus'`;
do
VERSION=`basename $VERSION_DIR`
echo "Found version $VERSION of product $PACKAGE.$PRODUCT_ID"
# make version on bintray
VERSION_TMPL='{
"name": "%s",
"desc": "%s"
}'
VERSION_DEF=`printf "$VERSION_TMPL" $VERSION "$VERSION release of $PACKAGE:$PRODUCT_ID"`
VERSION_URL="$BINTRAY_API/packages/$BINTRAY_REPO/$PROJECT_ID/versions"
echo "Posting $VERSION_DEF to $VERSION_URL"
curl -H "Content-Type: application/json" -d "$VERSION_DEF" -u$BINTRAY_USER:$BINTRAY_TOKEN $VERSION_URL
echo ""
for FILE in `find $VERSION_DIR -type f`;
do
URI="$BINTRAY_API/content/$BINTRAY_REPO/$PROJECT_ID/$VERSION/$FILE;publish=1"
echo "Uploading file $FILE to $URI"
curl -T $FILE -u$BINTRAY_USER:$BINTRAY_TOKEN $URI
echo ""
done
done
done
echo "+--------------------------------+"
echo "| Migration script finished! \o/ |"
echo "+================================+"
Upvotes: 1
Reputation: 22893
Currently there is no dedicated tool for that kind of migration. REST API is indeed the way to do it.
Upvotes: 1