gpt4 book ai didi

java - Maven:从存储库下载父 pom 会删除存储库标签

转载 作者:行者123 更新时间:2023-11-30 08:37:33 27 4
gpt4 key购买 nike

我有一个存储在远程 Artifactory 存储库中的父 pom。 parent-pom 定义了一个 <repositories>标记一些快照存储库,其中包含我的父 pom 的父级。

当我现在尝试使用我的 parent-pom 构建项目时,maven 在我的 Artifactory 存储库中正确地找到了 parent-pom 并下载了它。

在构建过程中,我的快照依赖项无法找到,因为最终在我的本地存储库中结束的父 pom 缺少 <repositories>标签。

如果我只运行 mvn clean install 就可以正常工作在 parent-pom 的目录中将其安装到本地,但从存储库下载它似乎摆脱了标签。

这在我看来像是一个错误,但也许我遗漏了一些东西,这是预期的行为?如果是这样,为什么?是否有一些解决方法可以让我们可以在父 pom 中定义存储库?

存储在 Artifact 服务器上的父 pom:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.M2</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>

<version>1.0.1</version>

<packaging>pom</packaging>

<name>example-parent</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<distributionManagement>
<repository>
<id>example-releases</id>
<name>example-releases</name>
<url>http://com.example/blabla</url>
</repository>
<snapshotRepository>
<id>example-snapshots</id>
<name>example-snapshots</name>
<url>http://com.example/blabla</url>
</snapshotRepository>
</distributionManagement>

</project>

构建我的子项目时从存储库下载的父 pom:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.M2</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>

<version>1.0.1</version>

<packaging>pom</packaging>

<name>example-parent</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>





<distributionManagement>
<repository>
<id>example-releases</id>
<name>example-releases</name>
<url>http://com.example/blabla</url>
</repository>
<snapshotRepository>
<id>example-snapshots</id>
<name>example-snapshots</name>
<url>http://com.example/blabla</url>
</snapshotRepository>
</distributionManagement>

</project>

(甚至包括标签曾经所在的一些空格)

最佳答案

Artifctory 可能会在某些情况下过滤掉存储库标签,请参阅 [RTFACT-5343] Artifactory removes the pom <repositories> tag when accessing from a virtual repository :

This is actually a feature of Artifactory to make sure maven will only work against your Artifactory server.

Once maven encounter the repository tag inside the pom it try to download the dependencies from this repositories, shortcutting your repository manager. The file it self is saved un touched inside the repository.

You can turn it off in the virtual repository config panel http://wiki.jfrog.org/confluence/display/RTF/Virtual+Repositories

关于java - Maven:从存储库下载父 pom 会删除存储库标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37110856/

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