Bintray似乎是一个很好的服务,并且有许多关于它们如何比使用Nexus更好的文章,但由于某些原因,没有迁移脚本或工具来实际将工件从Nexus移动到Bintray。我正在寻找一种解决方案,用于将Nexus存储库(私有或公共)迁移到Bintray而不会有太多麻烦。
我知道Bintray有REST API,似乎你可以编写一个可以创建项目版本的脚本,然后逐个从Nexus上传工件,但由于某些原因我不断从这个REST获得错误API并不能带有实际可行的东西。
答案 0 :(得分:1)
目前,没有用于此类迁移的专用工具。 REST API确实是这样做的方式。
答案 1 :(得分:1)
正如@JBaruch已经提到过没有工具可以做到这一点,所以我不得不编写脚本来做到这一点。脚本可能超级脆弱,缓慢且难以维护,因此请小心使用。另请注意,脚本非常基本,您可能需要手动修复一些内容。
# 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 "+================================+"