0
votes

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.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:

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

1
What i don't understand that you wrote multiple times that you have "distributionManagement". Does that mean you have that really multiple times in your pom's? If so than just define the distribution management only once in your commons-parent pom. - khmarbaise
You wrote that commons-cli just packages a CLI test program? Does that mean for integration testing ? - khmarbaise
Ok, I was not sure if distribution management gets inherited. - tapasvi
commons-module1-core can be used as part of other module or can also be used standalone (through command line programs)..when used in standalone mode, I basically use maven assembly, which puts cli and core jars in classpath and packages a batch file / shell script to run the client program - tapasvi
To create a cli thing you should take look into the maven-appassembler plugin which supports you in creating batch-files / shell-files for calling your java project in a very handy way. - khmarbaise

1 Answers

0
votes

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>