0

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

Community
  • 1
  • 1
tapasvi
  • 322
  • 1
  • 7
  • 15
  • 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 Aug 17 '11 at 16:20
  • You wrote that commons-cli just packages a CLI test program? Does that mean for integration testing ? – khmarbaise Aug 17 '11 at 16:21
  • Ok, I was not sure if distribution management gets inherited. – tapasvi Aug 17 '11 at 16:29
  • 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 Aug 17 '11 at 16:31
  • 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 Aug 17 '11 at 16:49

1 Answers1

0

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>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I will try and upgrade to maven 3. I was initially put off because we do use site reports heavily. And I remember there were some issues when I scheduled a hudson job with mvn clean package site...by the way, why do you suggest I remove version from the child module? can they not have separate life cycles and versions than the parent module? – tapasvi Aug 17 '11 at 16:27
  • This is to confirm that upgrading to maven3 worked. Thank you, khmarbaise. I will deal with other maven3 site generation issues later..this was more important :) – tapasvi Aug 17 '11 at 16:38
  • If you thinking of having separate live cycle than the modules should not be hold together in a tree like the one your are using. This is a multi-module build which means in Maven World to have the same version number which make sense. If you need to have the parts different life cylce use simple separate modules. – khmarbaise Aug 17 '11 at 16:47
  • The Maven Site in Maven 3. works better than in Maven 2, cause they separated the Site generation from the core of Maven...only one issue you have to be a ware of that you use the correct version of the Maven -Site -Plugin (3.0 obviously). – khmarbaise Aug 17 '11 at 16:47