Missing Maven Dependencies in Eclipse Multi-Module Project

Im using STS 2.9.1 (build on Eclipse 3.7.2) with the m2e plugin bundled with STS (v1.0.200.20111228-1245).
I have a problem with missing dependencies in an Eclipse project that contains several modules, or maybe I do not fully understand how this should work.

His project is maven.
In my project> Properties> Java Build Path> Libraries I have the "Maven Dependencies" library, but it is empty (and this is the problem).
The main POM has no dependencies, but it has several modules declared in it. Adding a dependency to POM modules does not add it to the "Maven Dependencies" library (as I expected) and causes Eclipse to show errors in the source files.
Adding a dependency to the main POM adds it to the "MD" lib, but of course I do not want to add all the dependencies of my modules to the main POM just to have it in the "MD" lib and adding every single dependency to the Build The path does not seem correct and practical.

Ive tried:

  • Project> Clear,
  • Maven> Update Dependencies,
  • Maven> Update project configuration,
  • Uncheck the box: Project> Properties> Maven> Allow Workspace Project Dependencies.

None of the above looks like a trick.

Example:
Simplified project structure:

  • simple.project
    • ...
    • sample module
      • ...
      • pom.xml
    • pom.xml

simple.project / pom.xml:

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>simple.project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>sample-module</module>
    </modules>
    <dependencies>
        <dependency><!-- This dependency is present in "MD" lib. -->
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

simple.project / sample module / pom.xml:

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>simple.project</artifactId>
        <groupId>test</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>test</groupId>
    <artifactId>sample-module</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <dependencies>
        <dependency><!-- I've expected this dependency also to appear in "MD" lib. -->
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
+3
source share
3 answers

It should not work. A project imports a dependency on another if it depends on that project (using dependency) or if it inherits it (using parent). An element modulerepresents only aggregation .

+1
source

, Maven Project Maven Modules: " > ... > Maven > Maven Module". .

+1

, , , pom. <dependencyManagement> (. doc). , .

, . maven . , Eclipse, , .

, , .

The fact that the Maven dependency library is empty means that the Eclipse Maven plugin does not correctly resolve your poms. I had a good impression of the built-in STS maven plugin. Try downgrading it to m2e version 0.10. You only need to open STS DashBoard / Find Updates / Install m2e 0.10

I hope some of these tips help you.

0
source

All Articles