Search code examples
javaeclipsemavenm2eclipse

Why does eclipse not recognize Java nature of a multimodule maven project if name template is added to it?


I've a springboot project which is organized as multiple modules. I'm using Eclipse 2019-06 (version 4.12) with jdk 1.8 update 131 and apache maven 3.3.9 version.

While importing the project using Maven -> Existing maven projects -> select all project and module level poms->click on finish button, it does the import successfully.

I can view the child modules as separate projects that can be individually run by right clicking on them to project workspace. JUnit tests successfully run using right click -> Run As -> JUnit test.

But if i include a name template while importing the project, the child modules are not recognized even though I select all the child poms also while importing.

Java files show empty J which indicates that it doesn't recognize the Java nature. Because of this, I am unable to run JUnit tests and ctrl+click to navigate to a method or class is also not working.

In both cases, the contents of .project remain the same:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>my-springboot-app</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
    </natures>
</projectDescription>

I tried the following steps as suggested in other stackoverflow threads:

  1. Manually edit the above xml to add Java nature tags along with maven. This didnt help as somehow it started showing the corresponding child projects as packages instead of modules in the project/package explorer.
  2. Convert the project to a faceted one. This started showing up more errors as Java nature of the project was still not recognized by maven.
  3. Use mvn eclipse:clean or remove.project file from the code location and then use mvn eclipse:eclipse. This just recreated the .project file and didn't help for importing the child projects successfully.

Note that eclipse builds the project while importing it when I do not import the project specifying a name template for it but not otherwise.

It would be nice if someone could let me know if that is a problem with m2e plugin itself and that whether I should use another plugin instead.

Eclipse 4.12 comes with m2e pre-installed with it. I thought of using a name template instead of switching workspaces which could take time so that 2-3 flavours of my code can be seen in the same eclipse workspace.


Solution

  • The problem was with custom name being used as name template. When I use any of the available options like [groupid].[artifactid]-version or just the [artifactid]-version, m2e successfully imports the project. I saw some errors in the earlier project with respect to import class resolution but they went away when i closed unrelated projects in workspace.