3

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

Achi Even-dar
  • 427
  • 1
  • 10
  • 20
  • How is CHILD supposed to _inherit_ from PARENT? There's no [`parent`section](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance) in it. At least not in your code above. I also miss the two other essential parts of the [Maven Coordinates](https://maven.apache.org/pom.html#Maven_Coordinates): `` and `.` – Gerold Broser Jun 08 '15 at 15:38
  • @GeroldBroser you are right, I will edit it – Achi Even-dar Jun 09 '15 at 06:29
  • @GeroldBroser - edited, please let me know if still something is missing. – Achi Even-dar Jun 09 '15 at 06:51
  • I guess you've read [Apache Maven Eclipse Plugin, Introduction](https://maven.apache.org/plugins/maven-eclipse-plugin/) and its [eclipse:eclipse](https://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html) page. Note from the first: _"Disclaimer: Users are advised to use m2e, the [Eclipse Maven Integration](https://projects.eclipse.org/projects/technology.m2e) instead of this plugin"._ What do you exactly mean by **$someflag**? the `eclipse:eclipse` goal has a bunch of _parameters_ no flags. – Gerold Broser Jun 09 '15 at 09:13
  • @Gerold Broser. in my case **$someflag=-Paide-sagit**. My project at work is working with mvn eclipse:eclipse, so I can'tconvert it. What I am trying to understand is the connection between the pom.xml dependencies and the java build path and classpath, cause I see they are not "the same" – Achi Even-dar Jun 09 '15 at 11:36
  • So you use [build profiles](https://maven.apache.org/guides/introduction/introduction-to-profiles.html), too. I'd say without seeing the concrete declarations in the various `.xml`s and the result of the invocation it's almost impossible to say why they are not "the same". – Gerold Broser Jun 09 '15 at 12:03

1 Answers1

0

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.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107