Azure Devops(十五) 使用Azure的私有Maven仓库
上一篇文章中,我们介绍了如何使用Azure的nuget仓库,今天我们来研究一下如何使用azure给我们提供的maven仓库。
首先,我们打开azureDevops,点击到制品界面,然后选择maven。
这里和nuget一样,如果你本地没有安装maven需要先安装maven的环境和JDK的相关环境,如果有的话就不需要安装了,如果你电脑上安装了IDEA的话可以直接使用IDEA自带的maven,免去安装的步骤,我们本篇文章重点在于讲述如何使用auzre的私有maven仓库,所以maven的相关安装操作就不在赘述了,需要的小伙伴请自行搜索。
这里为了简便性和通用性,我们使用IDEA自带的MAVEN来演示这个操作,类比自己的环境也是一样的。
首先我们先新建一个标准的maven项目,我这里直接使用了springboot的模板,当然其他模板也是可以的只要是一个证可以正常进行编译的maven项目都可以。
然后我们打开项目的POM.xml按照azure的要求在文件中添加以下配置内容
<repository>
<id>artanis</id>
<url>https://pkgs.dev.azure.com/artanis-c/my-devops/_packaging/artanis/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
这个配置节表明了我们要使用的仓库地址,并且志明了,不管是release还是snapshots都会使用我们这个仓库,如果说我们在实际开发中有要求,只有开发或者生产可以使用这个仓库我们可以更改对应的配置节来启动和停用。
我们打开POM.xml添加repositories和distributionManagement两个节点,并且把上面的配置项添加到里面去,实例文件如下所示。
这里要注意distributionManagement里是不包括release的要去掉。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>azure_maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>azure_maven</name>
<description>azure_maven</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>artanis</id>
<url>https://pkgs.dev.azure.com/artanis-c/my-devops/_packaging/artanis/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>artanis</id>
<url>https://pkgs.dev.azure.com/artanis-c/my-devops/_packaging/artanis/maven/v1</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
这里添加好之后,我们需要去修改maven的setting.xml,如果你使用的机器上自己安装的maven这个配置文件一般在你用户文件夹的.m2文件夹下,windows对应用户文件夹。
如果是使用的IDEA我们按照下列步骤进行更改
需要在文件中找到servers节点,并且在其中添加如下配置
<servers>
<server>
<id>artanis</id>
<username>artanis-c</username>
<password>[PERSONAL_ACCESS_TOKEN]</password>
</server>
</servers>
这里是告诉maven,我们要从这个服务器获取Maven的依赖,你会发现这里的id和上面添加的repository的id是一致的。password可以使用我们之前为流水线生成好的token,如果你忘记了token,可以点击进行重新生成一个,实例的setting配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--> <!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.conf}/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
--> <!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
--> <!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
--> <!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups> <!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies> <!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<server>
<id>artanis</id>
<username>artanis-c</username>
<password>a3dshbgfbpzqqmzrru6rfpx3geaodfs3oqixgkexq7vzwuseiyza</password>
</server>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
--> <!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
</servers> <!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
|-->
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors> <!-- profiles
| This is a list of profiles which can be activated in a variety of ways, and which can modify
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
| specific paths and repository locations which allow the build to work in the local environment.
|
| For example, if you have an integration testing plugin - like cactus - that needs to know where
| your Tomcat instance is installed, you can provide a variable here such that the variable is
| dereferenced during the build process to configure the cactus plugin.
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular value for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the POM.
|
|-->
<profiles>
<profile>
<repositories>
<repository>
<id>artanis</id>
<url>https://pkgs.dev.azure.com/artanis-c/my-devops/_packaging/artanis/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories> </profile>
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
<profile>
<id>jdk-1.4</id> <activation>
<jdk>1.4</jdk>
</activation> <repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
--> <!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id> <activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation> <properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
--> </profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
--> </settings>
配置文件配置完成后,我们运行maven的deploy,查看一下运行的效果。
可以看到,maven已经把编译好的jar包上传到了我们私有仓库里去,然后我们随便找个其他的项目引用一下这个依赖看看。
可以看到,依赖已经成功的被获取了下来。
Azure Devops(十五) 使用Azure的私有Maven仓库的更多相关文章
- Azure DevOps (十二) 通过Azure Devops部署一个SpringBoot应用
文章配套视频专栏: https://space.bilibili.com/38649342/channel/seriesdetail?sid=2267536 视频正在努力更新. 上一篇文章中,我们通过 ...
- Azure Devops(十四) 使用Azure的私有Nuget仓库
哈喽大家好,最近因为工作的原因没有时间写文章,断更了俩月,今天我们开始继续研究Azure上的功能. 今天我们开始研究一下Azure的制品仓库,在之前的流水线的相关文章中,我们都使用到了制品仓库用来保存 ...
- Android业务组件化之Gradle和Sonatype Nexus搭建私有maven仓库
前言: 公司的业务组件化推进的已经差不多三四个月的时间了,各个业务组件之间的解耦工作已经基本完成,各个业务组件以module的形式存在项目中,然后项目依赖本地的module,多少有点不太利于项目的并行 ...
- Azure DevOps 跨账号连接 Azure 服务
一,引言 由于新申请的 Azure DevOps 账号中的私有项目不在享受托管代理提供的1800分钟的免费时间,又不想花钱付费,那我们只能另想版本解决没有并行作业的问题. -------------- ...
- 私有Maven仓库安装和使用
安装 这里选择安装的是windows平台,linux安装类似,下载可能要梯子 官网下载页 https://help.sonatype.com/repomanager2/download 下载链接 ht ...
- Azure DevOps (十) 通过流水线完成Docker镜像的部署
上一篇文章中,我们通过azure的流水线完成了镜像推送到镜像仓库中去,本篇文章我们继续开始完成下一步,通过流水线把镜像从仓库拉取到任意一台公网的服务器上去, 完成镜像部署的闭环. 首先我们需要先准备一 ...
- nexus 私有 maven 仓库的搭建
下载地址 页面 : https://help.sonatype.com/repomanager3/download 首先需要安装jdk .安装棒法我 前面的文章有写.https://www.cnblo ...
- Azure Terraform(五)利用Azure DevOps 实现自动化部署基础资源
一,引言 上一篇我们结合学习 Azure Traffic Manger 的内容,做了一个负载均衡的基础设施架构.通过 Terraform 部署执行计划,将整个 Azure Traffic Manage ...
- Azure 实践(1)- Azure Devops Server 安装
1.Azure Devops介绍 Azure DevOps Server 2020 (之前的名称为TFS),作为微软Azure DevOps 的企业私有(on-premises)服务器,是一个为开发团 ...
随机推荐
- Linux下切换root用户提示Authentication failure错误的解决方法(亲测有效)
第一种情况可能是root密码输入错误造成的,再仔细检查一遍是否输入错误 第二种是刚安装完,没有设置root用户密码导致的,我的就是最小化安装,就会出现这种小问题 解决办法:sudo passwd 然后 ...
- mongodb 复杂查询
记录一下工作中用到的 mongodb 复杂查询 aggregate 筛选 === 等于 { $match: { name: "bob" } } !== 不等于 { $match: ...
- 玩转ASP.NET 6.0框架-序言
ASP.NET Core是微软提供的强大的web框架,它有很多潜在的强大而有用的功能. 本专栏的目标是帮助您把框架的隐藏能力最大限度地发挥出来,让您能够按需定制ASP NET Core框架.本专栏提供 ...
- 关于一些lrzsz的知识
问题:如何从windows轻松上传文件到Linux? 方法:容器里面:apt-get update && apt-get install lrzsz 有yum的情况:yum -y in ...
- 【SpringSecurity系列3】基于Spring Webflux集成SpringSecurity实现前后端分离无状态Rest API的权限控制
源码传送门: https://github.com/ningzuoxin/zxning-springsecurity-demos/tree/master/02-springsecurity-state ...
- torch.cat()和torch.stack()
torch.cat() 和 torch.stack()略有不同torch.cat(tensors,dim=0,out=None)→ Tensortorch.cat()对tensors沿指定维度拼接,但 ...
- yum源更换/新
参考:https://www.cnblogs.com/opsprobe/p/10673031.html
- CF908D New Year and Arbitrary Arrangement 题解
\(0.\) 前言 有一天 \(Au\) 爷讲期望都见到了此题,通过写题解来加深理解. \(1.\) 题意 将初始为空的序列的末尾给定概率添加 \(a\) 或 \(b\),当至少有 \(k\) 对 \ ...
- c++ 超长整数减法 高精度减法
c++ 超长整数减法 高精度减法 实现思路 和加法类似,设置临时变量记录借位 当对应位数相减得到的结果大于等于0时,该位数字为本身值,否则需要加上借位的10.则\(t=(t+10)%10\) 打卡代码 ...
- Ubuntu 配置 .NET 使用环境
本文迁移自Panda666原博客,原发布时间:2021年3月29日. 说明 测试使用的环境 Linux版本:Ubuntu Server 20.04 LTS x64 .NET SDK版本:5.0 其他版 ...