2

I want to use the classes of one child module into another child module present in multi-module maven project. I have followed many existing solution. I am doing exactly same thing as in existing solution. But still it does not works.

Project structure:

Parent A: sampleproject
   |-- child A: Gui
   |-- child B: calculator

This is how pom.xml of parentA looks like:

  <groupId>com.example</groupId>
  <artifactId>sampleproject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
<modules>
  <module>Gui</module>
  <module>calculator</module>
</modules>

pom.xml of child A looks like:

  <parent>
    <groupId>com.example</groupId>
    <artifactId>sampleproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>Gui</artifactId>
  <packaging>jar</packaging>

<dependencies>
   <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>calculator</artifactId>
        <version>${project.version}</version>
        <type>jar</type>
   </dependency>
<dependencies>

pom.xml of child B looks like:

<parent>
<groupId>com.example</groupId>
<artifactId>sampleproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>calculator</artifactId>
<packaging>jar</packaging>

When I perform mvn install on parent project. jar files are created in calculator/target/name_of_jar.jar and Gui/target/name_of_jar.jar. But when I check in maven dependencies of Gui project, only directory of calculator is created rather than jar file.

Here is image of maven dependencies in Gui project. calculator jar file is not appearing in maven dependencies of <code>Gui</code> project

Links I have followed: use-a-class-from-the-other-child-module-in-maven and share-classes-within-modules-in-maven-project

Ahmed
  • 77
  • 5
  • `"when I check in maven dependencies of Gui project"`: do you mean using the eclipse maven "dependency tree" view? – ernest_k Jun 03 '18 at 12:58
  • yes. tab that is created in project. – Ahmed Jun 03 '18 at 12:59
  • When it displays a directory icon, it typically means that the dependency is resolved in the workspace, which is expected as both projects are modules of the same project. **Is code failing to compile**? – ernest_k Jun 03 '18 at 13:01
  • no there is no any error. when i perform ```mvn install``` entire project and individuals modules are being performed smoothly. – Ahmed Jun 03 '18 at 13:04
  • 2
    Can you then please explain what the exact problem is? – ernest_k Jun 03 '18 at 13:12
  • @ErnestKiwale jar file of ```calculator``` is not properly appearing in ```dependencies``` of ```Gui``` project. I have added image in edited version of post. Sorry for inconvenience. – Ahmed Jun 03 '18 at 14:12
  • 1
    please see my previous comment about workspace dependency resolution. Eclipse displays that when the dependency is found in the same workspace. You can disable this in maven or project settings, then you'd need to build using mvn to see your dependency jar listed like others – ernest_k Jun 03 '18 at 14:17
  • @Ahmed Can you tell why you have dependencies to wagon, aether, plexus, plexus-classwords ? I have my doubts if this are really your dependencies you seemed to me doing something wrong... – khmarbaise Jun 03 '18 at 14:17
  • Thanks very much @ErnestKiwele it worked. – Ahmed Jun 03 '18 at 17:02

0 Answers0