This is my first question on StackOverflow. Learnt quite a bit reading other Q&A so far.
Question is about Maven Multimodule.
Following is my project strurcture:
commons-parent |--pom.xml |--commons-module1 |--pom.xml |--core |--pom.xml |--cli |--pom.xml
cli stands for command line interface.
commons-module1 is a library to be used by different projects within company. commons-module1/core contains the pom which packages only the library classes. commons-module1/cli contains the pom which packages the command line test programs.
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.开发者_如何学Pythondef</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:
When a project needs to depend on commons-module1-core, project will have a maven dependency in pom as follows:
<dependency>
<groupId>com.abc.def</groupId>
<artifactId>commons-module1-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
This only works (i.e. dependencies satisfied) when the complete hierarchy commons-parent,commons-module1,commons-module1-core all three are in local repository. It doesn't work if I have any of them missing in local. We have nexus repository manager set up. So, my expectation was that, the project making use of commons-module1-core library can just declare above dependency snippet in their pom and through transitive dependency resolution, get the parent poms.
Am I missing something here?
EDIT
For a simpler use case which I think is similar to my problem - see this unanswered question:
Child not finding parent pom in flat structured multi module maven build
First of all, update to Maven 3.0.3 as soon as possible...2.1.0 has many bugs and will not be mantained any more. Second you are misusing some parts of the pom you always wrote:
<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>
But you should do it the following:
<parent>
<groupId>com.abc.def</groupId>
<artifactId>commons-module1</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>commons-module1-core</artifactId>
<packaging>jar</packaging>
精彩评论