1

I have a simple setup.

project
 |--> pom.xml
 |--> util
 |--> core
 |--> web

I managed to configure everything correctly. I changed the versions to 0.0.1-SNAPSHOT, I removed the dots from the project names (maybe Maven is picky without telling me, wrong guess) I changed the snapshot policy of artifactory to never.

I use Eclipse 4.3, and I verified that I am using the embedded maven version.

What I have is that it does find the parent and I can compile util. But when I want to compile the core project, Maven can not find it. It seams from the Debug output that it is looking for it in the local repository.

What do I need to do that Maven can find it right where it is in the other top level file.

All three projects are part of the <modules> section within the parent pom, and I do not need to use a local reference to the parent pom for Maven to locate it.

4

2 回答 2

3

如果我猜对了,你的 pom 文件应该如下所示。

考虑到 Maven 工件之间引用的不同含义:

  • 通过将子项目引用为 a <module>,父项目的构建project触发子项目的构建
  • project作为<parent>子项目的引用是为了让子项目从父项目继承定义

在许多情况下,您需要两个方向。

项目/pom.xml:

<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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>project</groupId>
    <artifactId>project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>util</module>
        <module>core</module>
        <module>web</module>
    </modules>
</project>

项目/util/pom.xml:

<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>project</groupId>
        <artifactId>project</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>util</artifactId>
</project>

项目/核心/pom.xml:

<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>project</groupId>
        <artifactId>project</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>core</artifactId>
    <dependencies>
        <dependency>
            <groupId>project</groupId>
            <artifactId>util</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

项目/web/pom.xml:

<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>project</groupId>
        <artifactId>project</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>web</artifactId>
    <dependencies>
        <dependency>
            <groupId>project</groupId>
            <artifactId>util</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>
于 2013-11-09T10:55:47.597 回答
1

首先,确保你有

<packaging>pom</packaging>

为你的根pom.xml

如果您不想确保您处于离线状态,您可以简单地添加-o,无需更改存储库设置。

mvn -o compile         <-- in the project root

这也是编译模块的首选方式。它们通常不是单独建造的。但是,如果您想编译util,请使用

mvn -pl util compile   <-- in the project root

同样适用于coreor web

于 2013-11-07T23:00:37.433 回答