Albaku
Albaku

Reputation: 84

Multi-module maven build : different result from parent and from module

I am migrating an application from ant build to maven 3 build. This app is composed by :

Here is an extract from my parent pom :

<groupId>com.test</groupId>
<artifactId>P</artifactId>
<packaging>pom</packaging>
<version>04.01.00</version>

<modules>
    <module>../PValidationJaxb</module> <-- jar
    <module>../PValidation</module> <-- ejb
    <module>../PImport</module> <-- war
    <module>../PTerminal</module> <-- war
    <module>../PWebService</module> <-- war
    <module>../PEAR</module> <-- ear
</modules>

I have several problems which I think have the same origin, probably a dependency management issue that I cannot figure out :

Do I miss something important in my configuration ?

The PValidation pom extract :

It is creating a jar containing an ejb with interfaces generated by xdoclet, as well as a client jar.

<parent>
    <groupId>com.test</groupId>
    <artifactId>P</artifactId>
    <version>04.01.00</version>
</parent>
<artifactId>P-validation</artifactId>
<packaging>ejb</packaging>

<dependencies>
    <dependency>
        <groupId>com.test</groupId>
        <artifactId>P-jaxb</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.5.ga</version>
        <exclusions>
            <exclusion>
                <groupId>cglib</groupId>
                <artifactId>cglib</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib-nodep</artifactId>
        <version>2.2.2</version>
    </dependency>
    ...
    [other libs]
    ...
</dependencies>

<build>
    ...
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <configuration>
                <ejbVersion>2.0</ejbVersion>
                <generateClient>true</generateClient>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xdoclet-maven-plugin</artifactId>
            ...

The PImport pom extract :

It depends on both Jaxb generated jar and the ejb client jar.

<parent>
    <groupId>com.test</groupId>
    <artifactId>P</artifactId>
    <version>04.01.00</version>
</parent>
<artifactId>P-import</artifactId>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>com.test</groupId>
        <artifactId>P-jaxb</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>com.test</groupId>
        <artifactId>P-validation</artifactId>
        <version>${project.version}</version>
        <type>ejb-client</type>
    </dependency>
    ...
    [other libs]
    ...
</dependencies>

The PWebService pom extract :

<parent>
    <groupId>com.test</groupId>
    <artifactId>P</artifactId>
    <version>04.01.00</version>
</parent>

<artifactId>P-webservice</artifactId>
<packaging>war</packaging>

<properties>
    <jersey.version>1.14</jersey.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>com.rte.etso</groupId>
        <artifactId>etso-validation</artifactId>
        <version>${project.version}</version>
        <type>ejb-client</type>
    </dependency>
    ...
    [other libs]
    ...
    <dependency>
        <groupId>org.mockejb</groupId>
        <artifactId>mockejb</artifactId>
        <version>0.6-beta2</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>cglib</groupId>
                <artifactId>cglib-full</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib-nodep</artifactId>
        <version>2.2.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Many thanks

Solution after modification of the configuration :

When I got the projects already mavenized, it didnt respect the folder layout convention, but as it was declared in the pom where to find the sources, I thought it would be working. Anyway, i changed it to match the recommended structure.

To build a single module I was executing mvn clean install directly at its level. It is this way I obtained a different result (which is in fact the one I wanted).

Anyway, my problem is solved, I put all the dependencies of the PValidation project as provided, as I am only including the generated client in other modules and they dont require all what is needed for the implementation.

But still I dont get why I had different result for the same configuration.

Upvotes: 2

Views: 1271

Answers (1)

khmarbaise
khmarbaise

Reputation: 97389

The first important thing is you should create the structure of your project appropriate to the modules structure which means having the following folder structure:

+-- parent
      +-- PValidationJaxb
      +-- PValidation
      +-- PImport
      +-- PTerminal
      +-- PWebService
      +-- PEAR

This means having a pom.xml which contains the modules definition in the parent folder. if you follow the above recommendation you can simplify the modules list to the following:

<modules>
    <module>PValidationJaxb</module> <-- jar
    <module>PValidation</module> <-- ejb
    <module>PImport</module> <-- war
    <module>PTerminal</module> <-- war
    <module>PWebService</module> <-- war
    <module>PEAR</module> <-- ear
</modules>

Furthermore a best practice in Maven is to use lowercase artifacts which mean in your case pvalidationjaxb instead of PValidationJaxb.

An other important thing is your version which does NOT follow the Maven conventions. Furthermore your version will be from the Maven point of view a release which is not the case you are doing development on this. In Maven you should use a so called SNAPSHOT for such purposes like 1.0.0-SNAPSHOT.

I hope you have followed the folder layout recommendation of Maven which says to put production code (which will be packaged into the resulting jar) into src/main/java whereas test code into src/test/java.

The problem you described having different dependencies sounds weired. The question is how have you tried to build a single moduel? This can usualy be achieved by using the following from the parent location:

mvn -pl module clean package

The problem with your unit tests sounds like a missing dependencies etc. but here is the questions how have you tried to run the unit tests and have you configured maven-surefire-plugin ? Or do you have integration tests? This is only a guess cause i don't see any configuration of Maven plugins in your poms.

Upvotes: 3

Related Questions