孩子没有在平面结构化的多模块maven构建中找到父pom

时间:2009-11-05 15:53:37

标签: maven-2

我正在设置一个具有扁平结构的多模块项目,即父级和子级位于同一个基本目录中。父级定义为

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>company</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1-0-SNAPSHOT</version>
    <name>child</name>
    <modules>
        <module>../child</module>
    </modules>
(...)

而孩子定义为

<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/maven-v4_0_0.xsd">
    <parent>
        <groupId>company</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
</parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>company</groupId>
<artifactId>child/artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>child</name>
(...)

(公司和项目名称混淆)

正在发生的事情是模块(孩子)抱怨它无法找到父母,即:

Reason: Cannot find parent: company:child for project: company:child:war:1.0-SNAPSHOT for project company:child:war:1.0-SNAPSHOT

是否有一个明显的解决方案,我错过了,或者建议使用扁平的项目结构?

修改 修正了错字。

3 个答案:

答案 0 :(得分:14)

使用Example 5Introduction to the POM中所述的<relativePath>元素:

<project>
  <parent>
    <groupId>company</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>.../parent/pom.xml</relativePath>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>company</groupId>
  <artifactId>child</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>child</name>
  ...
</project>

答案 1 :(得分:2)

父POM版本是1-0-SNAPSHOT,而不是1.0-SNAPSHOT。

答案 2 :(得分:0)

子pom不引用父pom,它引用另一个名为'build'的工件。它应该是:

<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/maven-v4_0_0.xsd">
    <parent>
        <groupId>company</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
</parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>company</groupId>
<artifactId>child</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>child</name>
(...)