2010-09-03 53 views
4

我有一个父项目,其中有5个子项也具有彼此之间的依赖关系。我在子节点pom.xml中使用了<parent>元素,并在父节点中使用了与<module>元素的聚合。当使用Maven构建子项目时缺少工件2

我父POM看起来是这样的:

<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>com.domain</groupId> 
<artifactId>Parent</artifactId> 
<packaging>pom</packaging> 
<version>RELEASE</version> 
<name>Parent</name> 

<modules> 
    <module>../Child1</module> 
    <module>../Child2</module> 
    <module>../Child3</module> 
    <module>../Child4</module> 
    <module>../Child5</module> 
</modules> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>com.domain</groupId> 
      <artifactId>Child1</artifactId> 
      <version>RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>com.domain</groupId> 
      <artifactId>Child2</artifactId> 
      <version>RELEASE</version> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 
</project> 

Child3 POM看起来是这样的:

<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>com.domain</groupId> 
<artifactId>Child3</artifactId> 
<name>Child3</name> 
<packaging>war</packaging> 

<parent> 
    <artifactId>Parent</artifactId> 
    <groupId>com.domain</groupId> 
    <version>RELEASE</version> 
</parent> 

<dependencies> 
    <dependency> 
     <groupId>com.domain</groupId> 
     <artifactId>Child1</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.domain</groupId> 
     <artifactId>Child2</artifactId> 
    </dependency> 
</dependencies> 
</project> 

一切工作正常,当我在家长或Child1运行mvn install。但是,当我在Child3运行它,我得到以下错误:

[INFO] Failed to resolve artifact. 
Missing: 
---------- 
1) com.domain:Child1:jar:RELEASE 
... 
2) com.domain:Child2:jar:RELEASE 

这有什么错我的建立?

回答

6

我不会真正尝试解决您当前的方法问题,而是会涵盖我认为是最佳实践的情况。你可以随意采用与否:)

首先,请注意RELEASE(和LATEST)是一个特殊的关键字(不知道你是意识到了这一点),并RELEASE以某种方式在这里被误用(家长用定义为RELEASE的版本没有意义)。无论如何,这些特殊的关键字是一个坏主意,为了构建可重复性,我们不推荐使用这些关键字(我不确定它们是否在Maven3中受支持),只是为了避免使用它们。

因此,使用快照版本,如果该项目正在积极开发中,而不是即修改这样的家长:

<project> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.domain</groupId> 
    <artifactId>Parent</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <name>Parent</name> 

    <modules> 
    <module>../Child1</module> 
    <module>../Child2</module> 
    <module>../Child3</module> 
    <module>../Child4</module> 
    <module>../Child5</module> 
    </modules> 

</project> 

注意,我删除了dependencyManagement元素,我不认为它提供了很多增值一个多模块构建的内部依赖和推荐使用的${project.groupId}${project.version}内置属性声明,而不是当他们:

<project> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
    <artifactId>Parent</artifactId> 
    <groupId>com.domain</groupId> 
    <version>1.0-SNAPSHOT</version><!-- must hard code this --> 
    </parent> 

    <!--groupId>com.domain</groupId--><!-- you can skip this, you inherit it --> 
    <artifactId>Child3</artifactId> 
    <packaging>war</packaging> 

    <name>Child3</name> 

    <dependencies> 
    <dependency> 
     <groupId>${project.groupId}</groupId> 
     <artifactId>Child1</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>${project.groupId}</groupId> 
     <artifactId>Child2</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    </dependencies> 
</project> 

正如我写的,我不认为使用dependencyManagement内部依赖关系非常有用,这就是我设置我的项目的方式。但你可以,如果你想。只需使用属性即可不重复信息。

+0

问题确实来自使用RELEASE作为版本号。 Merci Pascal。 – Damien 2010-09-07 15:25:36