这是我在StackOverflow上的第一个问题 . 到目前为止学到了很多其他问答 .
问题是关于Maven Multimodule .
以下是我的项目结构:
commons-parent
|--pom.xml
|--commons-module1
|--pom.xml
|--core
|--pom.xml
|--cli
|--pom.xml
cli代表命令行界面 .
commons-module1是公司内不同项目使用的库 . commons-module1 / core包含仅包装库类的pom . commons-module1 / cli包含打包命令行测试程序的pom .
commons-parent/pom.xml (relevant snippet):
<groupId>com.abc.def</groupId>
<artifactId>commons-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<profile>
<id>reactor</id>
<properties>
<env.type>dev</env.type>
</properties>
<modules>
<module>../commons-module1</module>
</modules>
</profile>
there is a distribution management section
but there is no repositories section in pom.
commons-module1/pom.xml (relevant snippet):
<parent>
<groupId>com.abc.def</groupId>
<artifactId>commons-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.abc.def</groupId>
<artifactId>commons-module1</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>cli</module>
<module>core</module>
</modules>
there is a distribution management section
but there is no repositories section in pom.
commons-module1/core/pom.xml (relevant snippet):
<parent>
<groupId>com.abc.def</groupId>
<artifactId>commons-module1</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.abc.def</groupId>
<artifactId>commons-module1-core</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
there is a distribution management section
but there is no repositories section in pom.
commons-module1/cli/pom.xml (relevant snippet):
<parent>
<groupId>com.abc.def</groupId>
<artifactId>commons-module1</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.abc.def</groupId>
<artifactId>commons-module1-cli</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
there is a distribution management section
but there is no repositories section in pom.
Environment:
Apache Maven 2.1.0 (r755702; 2009-03-18 19:10:27+0000)
Java version: 1.6.0_25
Problem Description:
当项目需要依赖于commons-module1-core时,项目将在pom中具有maven依赖关系,如下所示:
<dependency>
<groupId>com.abc.def</groupId>
<artifactId>commons-module1-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
当完整的层次结构commons-parent,commons-module1,commons-module1-core全部三个都在本地存储库中时,这只能工作(即满足依赖性) . 如果我在本地失踪了它们,它就无法工作 . 我们设置了nexus存储库管理器 . 所以,我的期望是,使用commons-module1-core库的项目可以在他们的pom中声明上面的依赖片段,并通过传递依赖性解析,获得父poms .
我在这里错过了什么吗?
EDIT
对于一个我认为与我的问题类似的更简单的用例 - 请参阅这个未解决的问题:
Child not finding parent pom in flat structured multi module maven build
1 回答
首先,尽快更新到Maven 3.0.3 ...... 2.1.0有很多错误,不再需要保留 . 其次,你在滥用你总是写的pom的某些部分:
但你应该做以下事情: