Maven:从存储库下载父pom会删除存储库标记

时间:2016-05-09 08:21:36

标签: java maven

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

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

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

如果我只在父pom的目​​录中运行mvn clean install以在本地安装它,它可以正常工作,但是从存储库下载它似乎摆脱了标记。

在我看来,这似乎是一个错误,但也许我错过了一些东西,这是预期的行为?如果是这样,为什么?我们可以使用一些解决方法来定义父pom中的存储库吗?

存储在artifactory服务器上的Parent-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>

(甚至包括以前标签的一些空格)

1 个答案:

答案 0 :(得分:2)

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

  

这实际上是Artifactory的一个功能,可以确保maven只能对你的Artifactory服务器起作用。

     

一旦maven遇到pom中的repository标记,它就会尝试从这个存储库下载依赖项,从而缩短存储库管理器的速度。它自己保存的文件没有在存储库中触及。

     

您可以在虚拟存储库配置面板中将其关闭   http://wiki.jfrog.org/confluence/display/RTF/Virtual+Repositories

相关问题