gpt4 book ai didi

java - Maven 项目无法从 Azure Artifacts 下载 Artifact

转载 作者:行者123 更新时间:2023-12-02 07:45:01 40 4
gpt4 key购买 nike

提出这个问题的另一种方式是:

如何验证maven使用 Azure 进行项目 personal access token这样Maven构建就可以下载artifacts发表于Azure Artifacts

我有个人访问 token ,用于进行身份验证。但问题是 pom.xml 是什么?这有助于maven项目进行身份验证。

或者更简单的话

如何配置 Maven 项目以从 Maven 中央存储库和一些私有(private) Artifact 发布者下载 Artifact 。就我而言,私有(private) Artifact 发布者是 Azure Artifacts。

最佳答案

首先在系统环境变量中设置您的 Azure 个人访问 token 。比如环境变量名称键是 AZURE_PAT然后在 settings.xml 中访问它

您只需在C:\Users\<UserName>\.m2下添加一个settings.xml即可

settings.xml会像

<settings>
<servers>
<server>
<id>AzureRepo</id>
<username>AZURE_ARTIFACTS</username>

<password>${env.AZURE_PAT}</password>

</server>

</servers>

</settings>

然后打开 pom.xml 并在 repositories 属性下添加以下存储库属性。您的 Azure Artifact URL 将由 Azure Artifact 提供。

    <repository>
<id>AzureRepo</id>
<url>Artifactory URL provided by Azure</url>
</repository>

所以你的 pom.xml 看起来像这样。顺便说一句,这个 pom.xml 有 spring 依赖项。

<?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.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.basic</groupId>
<artifactId>basic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>basic</name>
<description>basic maven project for Spring Boot</description>

<properties>
<java.version>11</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<id>Central Maven repository</id>
<name>Central Maven repository https</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
</repository>
<repository>
<id>AzureRepo</id>
<url>Artifactory URL provided by Azure</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>Central Maven repository</id>
<name>Central Maven repository https</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

这可以帮助您下​​载 maven 存储库中的 azure Artifact 。

关于java - Maven 项目无法从 Azure Artifacts 下载 Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62520794/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com