Branching Problems with a Multi-Module Maven Project

February 16, 2010

I was impressed last year when I found that the M2eclipse Eclipse plugin handled multi-module projects checked out of Subversion using Subclipse with ease.  Eclipse does not natively support a nested multi-module project structure recommended by Maven, and getting the two to work well together has historically been a pain.  M2eclipse has solved this by "mapping" the child modules of the project you are importing to sibling projects in your Eclipse workspace.  For example, lets take the following multi-module Maven project:

This project consists of one parent project (springapp) which has four child modules (core, model, utility and webapp).  In the second image below, you can see that when this project is imported into Eclipse using M2eclipse, 5 projects have been created.  There is one project for each of the child modules and one for the parent project.  As you can see from the expanded view of parent module, it still includes the directories of the child modules, even though they are also contained in sibling projects in Eclipse.  This is only moderately confusing.

View of project from Eclipse.

It has served us well and I haven't experienced any real issues until today.  As is common practice, I reached a point where I wanted take my work from the trunk and create a branch.  I had a bunch of working files not checked in, so I wanted to just create a branch right from my working directory.  There is this option in Subclipse to Branch/Tag (remember that in Subversion, the act of branching or tagging is essentially no different, both are simple copy commands to another directory).  So I went ahead and highlighted all Eclipse projects, right click on them and then choose the Branch/Tag option, following the wizard that walked me through the process.  When I was done and my code was branched, I felt pretty good, until I took a closer look at the code in the branch.

View of Subversion After bad Branching

If you compare the project structure in the trunk to the project structure in new-work-branch, focusing on the highlighted folder, you can see that something is amiss.  I checked in the 5 Eclipse projects as if they were separate modules of the springapp project instead of treating them like one project to check in.  Luckily I caught this before I did any real damage, although my solution was to remove the branch and start over again.  What I should have done was to select only the parent project when I started my branching effort, since the parent project in Eclipse encompasses all of the child projects as well.  Lesson learned!

While we could easily blame this problem on Maven for having a multi-module setup or even m2eclipse for allowing this happen, the truth is, the Eclipse platform should natively support hierarchical or nested project structures, like other IDE's do.  This has been a user request for some time, and with my experience today, I feel even more strongly about the need to make this change.

Share this:

comments powered by Disqus