multi module maven project with parent pom and svn layout

Casey picture Casey · Dec 14, 2010 · Viewed 14.2k times · Source

I currently have about 16 projects that I build with maven that get deployed to the same application server that make up something like a "portal". I have built a parent pom to handle common dependencies and plugin configurations. Currently, my SVN structure looks similar to this:

portal_root
    +project1
        +tags
        +branches
        +trunk
    +project2
        .
        .
        .
    +projectn
    pom.xml

The individual projects are each separately deployed. That is, project1 doesn't have a dependency on project2 and each can be modified and deployed without having to modify anything else.

This presents a problem with SVN as if another developer wanted to check out the entire "portal" root (to also get the parent pom) they would also by default pull down copies of all the tags and branches! Not really ideal.

The only other thing I can think of is to use something like this:

 portal_root
     +tags
     +branches
     +trunk
         +project1
              +src
              pom.xml
         +project2
             .
             .
             .
         pom.xml

However, now all project changes will be tracked in the tags folder. This isn't a huge problem for me, but branching now seems to become a pain.

I am also currently working on hooking up Teamcity into this as well which would be a bit easier now, since I would only have to watch a single directory (e.g. tags) to catch everything that needs to be built. I am also deploying artifacts to a enterprise Nessus repository.

I'm hoping someone could give me some suggestions here as I have been unable to find any decent documentation that talks about the entire build lifecycle and best practices here.

I like the idea of being able to build and deploy all the projects with a single maven command. I also like having all the common dependencies, repository information and plugin information in one place.

Answer

Ali Shakiba picture Ali Shakiba · Dec 14, 2010

You can use following layout:

+parent-project
  pom.xml
+child-project-1
  pom.xml
+child-project-2
  pom.xml

In parent project pom add:

<modules>
    <module>../child-project-1</module>
    <module>../child-project-2</module>
</modules>

In children projects pom add:

<parent>
    <artifactId><!-- parent artifactId --></artifactId>
    <groupId><!-- parent groupdId --></groupId>
    <version><!-- parent version --></version>
    <relativePath>../parent-project</relativePath>
</parent>

Children Projects can optionally be dependent.

Following links may also help: