在Azure DevOps Server 中提交Maven 依赖包(mvn deploy-file)

Contents

1. 概述
2. 必要准备
安装Java
下载安装Maven
3. 服务器配置
新建连接源
4. 客户端配置
5. 上传maven包文件
6. 常见问题
Maven最新版本3.6.2出现异常

1. 概述

Azure DevOps Server (TFS)可以实现多种依赖包的托管服务器,例如NuGet、NPM、Maven、Python、Gradle、Azure通用包等。其中Maven库是许多Java开发人员最为熟悉的一种库,Azure DevOps Server提供了一种类似与Maven私服(例如Nexus)的保管理服务。开发人员可以从Azure DevOps Server中获取软件系统依赖的第三方软件包,也可以将自己开发的公共软件包发布到Azure DevOps服务器上,分享给其他开发团队。

Azure DevOps中的Maven包管理,遵循标准的Maven包管理协议,开发人员可以使用任何标准的maven工具上传和下载依赖包。比较常见的依赖包管理有两种方式:在编译流程中自动发布包文件;使用maven插件deploy-file将已经存在的包文件发布到服务器上。

如果需要了解在编译流程中发布maven包,可以参考 Azure DevOps Server

本文主要介绍如何使用maven插件deploy-file将已经存在的包文件发布到服务器上。

2. 必要准备

  • 安装Java

在本文中,我们使用64位java,1.8.0

C:\apache-maven-3.6.2\bin>java -version java version "1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)


  • 下载安装Maven

在本文中,我们使用了Maven版本3.6.0,当前最新的版本3.6.2出现异常,参考后面的常见问题描述。

3. 服务器配置

新建连接源

image

配置名称和权限

扫描二维码关注公众号,回复: 7369723 查看本文章

image

生成Maven认证信息

image

image

复制在服务器中生成的Maven认证信息,并将其配置到本地计算机的Maven配置文件settings.xml中

image

4. 客户端配置

使用文本编辑器打开本地计算机中的Maven配置文件,并将上面生成的认证信息粘贴到文档中的Servers节点中

image

5. 上传maven包文件

首先我们需要准备好已经存在的Maven包文件,例如下面的的操作中,我们使用从互联网下载的包文件ckfinder.jar
我们编写好下面的命令行脚本

mvn deploy:deploy-file -DgroupId=com.ckfinder -DartifactId=ckfinder -Dversion=2.6 -Dpackaging=jar -DrepositoryId=tfs-net-com-cn-collection-c-maven -Dfile=D:\temp\ckfinder.jar -Durl=http://tfs.net.com.cn:8080/tfs/Collection/_packaging/maven/maven/v1

需要对上面的几个关键参数做一些说明:
  • repositoryId:本地Maven配置文件中的server节点名称,也是上面章节中从Azure DevOps服务器中获取的认证信息中的服务器名称;Maven会按照这个名称查询到认证信息,提交给服务器
  • file:本地计算机中存贮依赖包文件的完整路径
  • url:Azure DevOps Server中的Maven库服务器地址

如果需要了解更多的参数,请参考maven的官方文档:

6. 常见问题

Maven最新版本3.6.2出现异常

C:\apache-maven-3.6.2\bin>mvn deploy:deploy-file -DgroupId=com.ckfinder -DartifactId=ckfinder -Dversion=2.6 -Dpackaging=jar -DrepositoryId=tfs-mc-net-智能软件公司-zhanghongjun -Dfile=D:\temp\htmlparser.jar -Durl=http://tfs.mc.net:8080/tfs/智能软件公司/_packaging/zhanghongjun/maven/v1 [INFO] Scanning for projects... [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom --- Uploading to tfs-mc-net-智能软件公司-zhanghongjun: http://tfs.mc.net:8080/tfs/智能软件公司/_packaging/zhanghongjun/maven/v1/com/ckfinder/ckfinder/2.6/ckfinder-2.6.jar Uploading to tfs-mc-net-智能软件公司-zhanghongjun: http://tfs.mc.net:8080/tfs/智能软件公司/_packaging/zhanghongjun/maven/v1/com/ckfinder/ckfinder/2.6/ckfinder-2.6.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.018 s [INFO] Finished at: 2019-09-26T17:28:41+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts: Could not transfer artifact com.ckfinder:ckfinder:jar:2.6 from/to tfs-mc-net-智能软件公司-zhanghongjun (http://tfs.mc.net:8080/tfs/智能软件公司/_packaging/zhanghongjun/maven/v1): Failed to transfer file http://tfs.mc.net:8080/tfs/智能软件公司/_packaging/zhanghongjun/maven/v1/com/ckfinder/ckfinder/2.6/ckfinder-2.6.jar with status code 400 -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.a

------------------------------------------------------------

http://www.cnblogs.com/danzhang/  DevOps MVP 张洪君

------------------------------------------------------------

猜你喜欢

转载自www.cnblogs.com/danzhang/p/11593771.html