views:

1454

answers:

6

We have a fairly large group of Maven2 projects, with a root POM file listing 10+ modules and a lot of properties used by the modules (dependency version numbers, plugin configuration, common dependencies, etc). Some of the modules are, like the root project, parents to other sets of modules.

To clarify, the root project and said parent projects are set to pom packaging (as opposed to e.g. jar).

Because there are many dependencies between the different projects, I like to use mvn eclipse:eclipse on the root project, which enables me to debug/step into any project at any time.

However, with this approach, the root POM itself, and all other pom-packaged projects, are unavailable in Eclipse. So, if I want to edit them, I have to open them some other way. This is becoming a bit of a hassle.

So, my question is: is it possible to somehow make pom-packaged projects available in Eclipse? If not, do you have any tips that could make my work with these projects easier?

For the record, I'm currently using MyEclipse 7.0.

A: 

You could try writing a task to manually create the .project file for each POM project in it's directory. Not sure on the specifics, but you could generate something like:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>${project.name}</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
        </buildSpec>
        <natures>
        </natures>
</projectDescription>

in the project's root directory and it should be okay.

I'm not sure whether doing this would then block you from importing the children projects into eclipse though (as you probably know - you need to import all your non-pom projects first and then create "general" projects for the others, with the path matching the physical path under the mvn structure). Eclipse will stop you from creating a project inside another, so if it recognises anything from higher in the project hierarchy you'll get headed off at the past.

Martin
A: 

I managed to work with codehaus eclipse plugin with maven projects having parents. The plugin has some flaws, but overall it is maintained and you should be able to get along with it.

Gennady Shumakher
+1  A: 

Well. Lots of people do this by making the parent POM a sibling project, and having a simple reactor POM in the root. However this can cause problems with website generation and the release plugin, as neither supports this mode as fully as one might like.

A big problem we often have is that people try to check out the trunk using Subclipse, which adds a .project file in the root, which then prevents importing projects below that level. Instead we have to go outside to check out, then import the projects.

I have heard rumor that Subversive might handle nested projects better, which is really the problem here. Other than that, I don't have an absolute solution here.

John Stoneham
+2  A: 

I tried this again, with Galileo and the latest version of m2eclipse. It is now possible to import Maven projects directly (without mvn eclipse:eclipse), and it turns out that the root POM is also imported as a project, which is excactly what I wanted.

Nils-Petter Nilsen
A: 

Generally I only really need the parent available in eclipse to add dependencies and to avail of the XML formatting. The cheap and cheerful way is to create resources project and link the parent pom into it. File -> New -> Other -> General -> File -> advanced

if you use the 2.8+ version of the eclipse plugin you can have it generate the link for you in each of your subprojects e.g.

<plugin>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.8-SNAPSHOT</version>
    <configuration>
        <linkedResources> 
            <linkedResource>
                <name>parent.xml</name> 
                <type>1</type>
                <location>${basedir}/${parent.relativePath}</location> 
            </linkedResource>
        </linkedResources> 
    </configuration>
  </plugin>

Though you will currently need to check it out from subversion and build it yourself as it doesn't seem to resolve from central yet.

svn co http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-eclipse-plugin/
cd maven-eclipse-plugin
mvn clean install
sgargan
A: 

Actually, if you don't want to depend on m2eclipse, the "right" way to do this is to use a flat project layout (as the problem is that Eclipse doesn't support nested projects).

Pascal Thivent