Tuesday Jan 08, 2008

Importing multiple same-named maven projects into one Eclipse workspace

When using Maven 2 for building Java projects and Eclipse for writing the code, a standard tool is the maven eclipse plugin (Note: not the eclipse maven plugin ;-), which is a plugin for Eclipse, although it can be useful too). It creates Eclipse projects from your Maven modules, which can then be imported into Eclipse as existing projects:

mvn eclipse:eclipse

(BTW: it's often useful to add -DdownloadSources=true which will download and set source and API attachements for the referenced libraries in Eclipse).

Now I often develop on both trunk and branch of a project at the same time, eg. for a merge. For this it is practical to have both code bases inside Eclipse, grouped by working sets, eg. "mylib trunk" and "mylib branch 1.3". Now the problem is that Eclipse does not allow you to import two projects with the same name into a single workspace, but exactly this happens when you run mvn eclipse:eclipse in both the trunk and branch of your project. Until now I had no solution to this, but today I came across this property for the maven eclipse plugin: projectNameTemplate. It allows you to change the Eclipse project name that is generated, which is by default only the artifactId, that is normally the same across different branches. Now I ran this for my 1.3 branch:

mvn -Declipse.projectNameTemplate=[artifactId]-1.3 eclipse:eclipse

This creates projects named like "mylib-1.3" and no longer collides with the "mylib" project from the trunk. Besides [artifactId], you can also use [groupId] and [version] as placeholders.

Comments:

Hey, that's an useful tip. Thank you very much.

Posted by Lars Trieloff on January 08, 2008 at 06:00 PM CET #

Post a Comment:
  • HTML Syntax: Allowed