How to compile dependency in maven?

List projects B and C as modules in the pom of the project A. Now when you build project A, it should build project B and C automatically and in the correct order.

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>multi</groupId>
    <artifactId>A</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>

    <modules>
        <module>B</module>
        <module>C</module>
    </modules>
</project>

If you want to build B and automatically build it's dependencies you can use the advanced options of the maven reactor like –-also-make-dependents .

mvn clean install –-projects B –-also-make 

Or short

mvn clean install -pl B -am

That will compile all submodules of A whose B depends on . There are a useful post on sonatype blog on the advanced options of maven reactor. http://www.sonatype.com/people/2009/10/maven-tips-and-tricks-advanced-reactor-options/

Tags:

Maven