Search code examples
javamavenm2e

Maven service used for dependency graph


Just downloaded the m2e Eclipse plugin and love it! I am wondering what web service it uses to resolve all of a project's transitive dependencies.

I assume that it works by parsing all of the <dependency> elements out of the project pom.xml, and uses a service to query Maven for each transitive dependency.

Basically, I'm asking: how does m2e populate the local Maven cache stored at ~/.m2?


Solution

  • The plugin works the same as the Maven command line progam mvn.

    Assuming your project's POM and Maven settings file does not change the default repository settings Maven will download files from Maven Central

    http://repo1.maven.org/maven2/

    So taking a dependency as follows:

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
    

    Maven will use the following URL convention (Maven2 repository layout):

    <Repository URL>/<groupId>/<artifactId>/<version>/<artifactId>-<version>.<packaging>
    

    To download 2 files:

    1. http://repo1.maven.org/maven2/log4j/log4j/1.2.16/log4j-1.2.16.pom
    2. http://repo1.maven.org/maven2/log4j/log4j/1.2.16/log4j-1.2.16.jar

    The first is the module POM, whose packaging element will indicate the file name extension to use when downloading the second file (defaults to "jar").

    Finally Maven will recursively read the POM files associated with other dependencies listed in the POM and decide which other modules to download (Dependencies of Dependencies)