将已有 Maven 私库迁移至云效

更新时间:
复制 MD 格式

本文介绍如何将已有Maven私库中的制品包批量迁移到云效的Maven私库中。

操作步骤

云效支持两种方式将Maven私库中的制品包批量迁移到云效的Maven私库中,您可以根据实际需求进行选择:

  • 本地文件批量上传。

  • Nexus3导入制品。

步骤一:下载迁移工具

工具下载地址:https://agent-install-beijing.oss-cn-beijing.aliyuncs.com/maven-migration-jar-with-dependencies.jar

通过上面地址将jar包下载到本地,保存为maven-migration-jar-with-dependencies.jar。

步骤二:运行下载工具

本地文件批量上传

请确保机器上安装了java8及以上版本,在当前jar包的目录下执行如下命令: 运行命令:java -jar maven-migration-jar-with-dependencies.jar migrate --help可以查看帮助信息。

java -jar ./target/maven-migration-jar-with-dependencies.jar migrate --help
Usage: migrate migrate [-hV] [--dryrun] [--exclude=<exclude>]
                       [--include=<include>] --source-dir=<sourceDir>
                       --target-repo-password=<repoPassword>
                       --target-repo-url=<repoUrl>
                       --target-repo-username=<repoUsername>
迁移制品
      --dryrun              试运行,不会真正上传包
      --exclude=<exclude>   排除的groupId,多个groupId以逗号分割
  -h, --help                Show this help message and exit.
      --include=<include>   包含的groupId,多个groupId以逗号分割
      --source-dir=<sourceDir>
                            源文件目录,比如~/.m2/repository
      --target-repo-password=<repoPassword>
                            访问目标仓库的密码,可在packages.aliyun.com中仓库指
                              南中查看
      --target-repo-url=<repoUrl>
                            目标仓库地址,可在packages.aliyun.com中仓库指南中查
                              看
      --target-repo-username=<repoUsername>
                            访问目标仓库的用户名,可在packages.aliyun.com中仓库
                              指南中查看
  -V, --version             Print version information and exit.                      
     
重要

如果帮助信息中中文出现乱码,可先在命令行中执行chcp 65001,然后再执行Java命令。

示例命令:

  java -jar maven-migration-jar-with-dependencies.jar  migrate --source-dir="/root/.m2/repository"  --target-repo-url="https://packages.aliyun.com/xxxxxx/maven/xxxxx-release-ogcezj"  --target-repo-username="672aca1cbecc93xxxxx" --target-repo-password="xxxxxxx" --include="com.taobao.text" --exclude="junit"

这条命令会将本地Maven仓库中groupIdcom.taobao.text下的所有包上传到当前仓库中。具体参数信息,可在制品仓库主页面,选择进入目标制品仓库,在中获取

Nexus3导入制品

请确保机器上安装了java8及以上版本,在当前jar包的目录下执行如下命令: 运行命令:java -jar maven-migration-jar-with-dependencies.jar migrateNexus --help可以查看帮助信息。

java -jar maven-migration-jar-with-dependencies.jar migrateNexus --help
Usage: migrate migrateNexus [-hV] [--dryrun] [--exclude=<exclude>]
                            [--include=<include>] --nexus-host=<nexusHost>
                            --source-repo-id=<repoId>
                            --source-repo-password=<repoPassword>
                            --source-repo-username=<repoUsername>
                            --target-repo-password=<repoPassword>
                            --target-repo-url=<repoUrl>
                            --target-repo-username=<repoUsername>
迁移nexus3制品
      --dryrun              试运行,不会真正上传包
      --exclude=<exclude>   排除的groupId,多个groupId以逗号分割
  -h, --help                Show this help message and exit.
      --include=<include>   包含的groupId,多个groupId以逗号分割
      --nexus-host=<nexusHost> nexus服务器地址
      --source-repo-id=<repoId> 源仓库Id
      --source-repo-password=<repoPassword> 访问源仓库的密码
      --source-repo-username=<repoUsername> 访问源仓库的用户名 
      --target-repo-password=<repoPassword> 访问目标仓库的密码,可在packages.aliyun.com中仓库指南中查看
      --target-repo-url=<repoUrl> 目标仓库地址,可在packages.aliyun.com中仓库指南中查看
      --target-repo-username=<repoUsername> 访问目标仓库的用户名,可在packages.aliyun.com中仓库指南中查看
  -V, --version             Print version information and exit.
重要

如果帮助信息中中文出现乱码,可先在命令行中执行chcp 65001,然后再执行Java命令。

示例命令:

  java -jar maven-migration-jar-with-dependencies.jar  migrateNexus --source-repo-id="maven-releases" --source-repo-username="admin" --source-repo-password="admin123" --nexus-host="http://localhost:8081" --target-repo-url="https://packages.aliyun.com/xxxxxxxx/maven/xxxxx-release-ogcezj"  --target-repo-username="672aca1cbecc93xxxxx" --target-repo-password="gKUf3xxxxx(" --include="com.taobao.text"

这条命令会将指定的Nexus仓库maven-releasesgroupIdcom.taobao.text下的所有包上传到当前仓库中。具体参数信息,可在制品仓库主页面,选择进入目标制品仓库,在中获取

步骤三:查看运行结果

出现migration is finished字样表示迁移已完成,即可在云效目标制品仓库中查看:

2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - D:\maven\maven_repository\xml-apis\xml-apis\1.0.b2\xml-apis-1.0.b2.pom.sha1 not match the include role or matched the exclude role, will be skipped. GAV info: {"artifactId":"xml-apis","baseVersion":"1.0.b2","extension":"pom.sha1","groupId":"xml-apis","signature":false,"snapshot":false,"version":"1.0.b2"}
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - current path: xml-apis\xml-apis\1.0.b2\_remote.repositories, normalizedPath: xml-apis\xml-apis\1.0.b2\_remote.repositories, unixPath: xml-apis/xml-apis/1.0.b2/_remote.repositories
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - current path: xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar, normalizedPath: xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar, unixPath: xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - D:\maven\maven_repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar not match the include role or matched the exclude role, will be skipped. GAV info: {"artifactId":"xml-apis","baseVersion":"1.3.04","extension":"jar","groupId":"xml-apis","signature":false,"snapshot":false,"version":"1.3.04"}
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - current path: xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar.sha1, normalizedPath: xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar.sha1, unixPath: xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar.sha1
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - D:\maven\maven_repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar.sha1 not match the include role or matched the exclude role, will be skipped. GAV info: {"artifactId":"xml-apis","baseVersion":"1.3.04","extension":"jar.sha1","groupId":"xml-apis","signature":false,"snapshot":false,"version":"1.3.04"}
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - current path: xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.pom, normalizedPath: xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.pom, unixPath: xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.pom
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - D:\maven\maven_repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.pom not match the include role or matched the exclude role, will be skipped. GAV info: {"artifactId":"xml-apis","baseVersion":"1.3.04","extension":"pom","groupId":"xml-apis","signature":false,"snapshot":false,"version":"1.3.04"}
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - current path: xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.pom.sha1, normalizedPath: xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.pom.sha1, unixPath: xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.pom.sha1
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - D:\maven\maven_repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.pom.sha1 not match the include role or matched the exclude role, will be skipped. GAV info: {"artifactId":"xml-apis","baseVersion":"1.3.04","extension":"pom.sha1","groupId":"xml-apis","signature":false,"snapshot":false,"version":"1.3.04"}
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - current path: xml-apis\xml-apis\1.3.04\_remote.repositories, normalizedPath: xml-apis\xml-apis\1.3.04\_remote.repositories, unixPath: xml-apis/xml-apis/1.3.04/_remote.repositories
2024-12-05 10:30:52 [main] INFO com.alibaba.aone.maven_migration.command.MigrateCommand - migration is finished

目标仓库包列表页面显示已成功导入的 commons 系列 Maven 制品,包括 commons-validator、commons-logging、commons-lang、commons-io、commons-codec 等包及对应版本号。