Saturday, December 17, 2005

Maven 2 - How To: Multiple Module (flat project layout)

1) Create at least two Maven projects in a flat project layout...

%PROJECT_WORKSPACE%\%YOUR_PROJECT_MASTER%pom.xml
...

%PROJECT_WORKSPACE%\%YOUR_PROJECT_SLAVE%pom.xml
...

2) Define the <groupId> and <artifactId> of the modules...

%PROJECT_WORKSPACE%\%YOUR_PROJECT_MASTER%\pom.xml:

<project>
...
<groupId>somegroup.master</groupId>
<artifactId>master</artifactId>
...
</project>

%PROJECT_WORKSPACE%\%YOUR_PROJECT_SLAVE%\pom.xml:

<project>
...
<groupId>somegroup.slave</groupId>
<artifactId>slave</artifactId>
...
</project>

3) Define the modules in the master project...

Here I added first the artifactId, but it didn't work. I changed it to the directory and everything was fine.

%PROJECT_WORKSPACE%\%YOUR_PROJECT_MASTER%\pom.xml:

<project>
...
<modules>
<module>../%YOUR_PROJECT_SLAVE%</module>
</modules>
...
</project>

4) Add the <parent> and <dependency> element in the slave module...

%PROJECT_WORKSPACE%\%YOUR_PROJECT_SLAVE%\pom.xml:

<project>
...
<parent>
<groupId>somegroup.master</groupId>
<artifactId>master</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
...
<dependencies>
<dependency>
<groupId>somegroup.master</groupId>
<artifactId>master</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
</dependencies>
...
</project>

5) Call mvn install...

First the master project will be called and than slaven... That's it :)

* * *

References:

- http://maven.apache.org/
- http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
- http://maven.apache.org/guides/mini/guide-ide-eclipse.html

No comments: