【问题标题】:Locating the project.parent's POM定位 project.parent 的 POM
【发布时间】:2011-03-28 17:28:38
【问题描述】:

我在一个包含许多模块的项目中使用 Maven。当我们发布时,我们将模块部署到我们自己的 Maven 存储库。项目模块继承自父项目,父项目定义了常用属性,例如要使用的报告工具、SCM 位置、存储库等。

./pom.xml

<project>
    <groupId>com.example</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version
    <repositories>
        <repository>
            <url>repo.example.com</url>
            ...
        </repository>
    </repositories>
    ...
</project>

./module/pom.xml

<project>
    <groupId>com.example</groupId>
    <artifactId>module</artifactId>
    <parent>
        <groupId>com.example</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>
    ...
</project>

事实证明,这种设置存在问题:当有人加入项目并尝试构建模块时,它会失败。这是因为parent 在其本地 Maven 存储库中不可用,并且无法获取,因为 repo.example.com 仅在父 POM 中定义

有没有明显的方法来解决这个问题,在每个模块的 POM 中定义&lt;repositories/&gt;

【问题讨论】:

    标签: inheritance maven-2 dependency-management circular-dependency


    【解决方案1】:

    parent 部分中,添加一个relativePath 元素,内容为..

    <parent>
        ...
        <relativePath>..</relativePath>
    </parent>
    

    【讨论】:

    • 如果 parent 及其 POM 也已签出,这肯定可以工作。这是推荐的吗?
    • @Alison 我一直在使用它。如果相对路径指向具有匹配坐标的父 POM(您仍然需要提供 groupId、artifactId 和父版本),它会阻止 Maven 检查存储库。
    【解决方案2】:

    您应该考虑在您自己的 Maven 存储库中部署父 pom.xml

    这样,即使新开发者的机器上没有这个父级,他第一次尝试编译你的一个模块项目时,Maven 会在他的本地存储库中下载父级pom.xml,然后 make它可用于模块。

    这应该可以解决您的问题。

    【讨论】:

    • 我们已将父代部署到我们的存储库,但我们的存储库并未在子代的 POM 中直接引用。
    • @Alison 你的存储库可以在开发者settings.xmlno?中定义?
    • 是的,虽然这是我想避免的“检查代码”之外的更多配置
    【解决方案3】:

    RelativePath 将起作用。但是,我更喜欢在 settings.xml 中设置存储库

    在我看来,检查父级是多余的,当它发生变化时你必须更新项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 2016-01-19
      • 2016-09-26
      相关资源
      最近更新 更多