@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 "+================================+"
REST API確實是這樣。你可以發佈一些你得到的具體錯誤,我們會讓你去嗎? – JBaruch
@Jaruaru我發佈了我的最終腳本,希望它能幫助其他人,或者可能是移植工具的開始。它最終幫助了我,解決了我使用API的問題。 – dant3