maven pom.xml dependencies order vs classpath/build path order

2.7k views Asked by At

I am trying to understand the connection between the dependencies in a project's pom.xml file and the order of the java classpath/build path (my question is also regarding the inheritance of poms).

So far I wasn't able to find a detailed step-by-step explanation.

I have noticed for sure that it's not "the same", meaning, sometimes dependencies I have in my pom.xml will not appear in the build path in eclipse or will not be in the same order(after committing mvn eclipse:eclipse -$someflag) .

Let's assume for example I have the following Parent pom:

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>SOME_GROUP_ID</groupId>
<artifactId>PARENT</artifactId>
<version>SOME_VERSION</version>
<name>${project.groupId}:${project.artifactId}</name>
<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>SOME_OTHER_ARTIFACT1</artifactId>
        <version>${project.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
<modules>
<module>CHILD</module>
</modules>
</project>

and that some other project's pom.xml inherits it:

<project>
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>SOME_GROUP_ID</groupId>
    <artifactId>PARENT</artifactId>
    <version>SOME_VERSION</version>
</parent>
<artifactId>CHILD</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>SOME_OTHER_ARTIFACT2</artifactId>
        <version>${project.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
</project>

My questions are: If I now run mvn eclipse:eclipse -$someflag on CHILD project:

  1. Should the build path for CHILD project contain: PARENT, SOME_OTHER_ARTIFACT1, SOME_OTHER_ARTIFACT2 for sure? not for sure? when and why one of them should/shouldn't appear in the build path?
  2. Should the classpath file for CHILD project contain: PARENT, SOME_OTHER_ARTIFACT1, SOME_OTHER_ARTIFACT2 for sure? not for sure? when and why one of them should/shouldn't appear in the build path?
  3. Is it related to the flag (i.e $someflag) that was used when running mvn eclipse:eclipse?
  4. Should the jars in the library appear also in the order of the dependencies in the project that is being initialized? i.e PARENT, SOME_OTHER_ARTIFACT1, SOME_OTHER_ARTIFACT2 (from top to bottom) necessarily? When and why should the order be different?

Thank you

1

There are 1 answers

0
Gerold Broser On

Re "my question is also regarding the inheritance of poms"

See Maven: The Complete Reference, Project Inheritance:

You can avoid repeating yourself if your projects make use of inheritance via the parent element. When a project specifies a parent, it inherits the information in the parent project’s POM. It can then override and add to the values specified in this parent POM.

... and Multi-module vs. Inheritance:

There is a difference between inheriting from a parent project and being managed by a multimodule project. A parent project is one that passes its values to its children. A multimodule project simply manages a group of other subprojects or modules.