Search code examples
javamavenmaven-3parent-childparent-pom

How to make existing maven parent project, child of newly created maven project


I have existing maven Project(named as projectB) that is parent of other Projects(projectC and projectD), and I want to make projectB as child of newly created maven Project(named as projectA). This is Directory structure:

projectA
  -> pom.xml
projectB
  -> pom.xml
projectC
  -> pom.xml
projectD
  -> pom.xml

This is how my pom.xml of projectA looks:

<modules>
    <module>projectB</module>
</modules>

And this is my pom.xml of projectB Looks:

    <parent>
        <groupId>(groupId of projectA)</groupId>
        <artifactId>projectA</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modules>
        <module>../projectC</module>
        <module>../projectD</module>
    </modules>

But when I perform make clean on projectA it gives me error:

Child module C:\Users\projectB of C:\Users\projectA\pom.xml does not exist

I have searched existing solutions, but none has helped me in solving the problem.


Solution

  • Since your all projects are all in the same level, you should have:

    In Project A:

    <modules>
        <module>../projectB</module>
    </modules>
    

    And in Project B:

    <parent>
        ...
        <relativePath>../projectA/pom.xml</relativePath>
    </parent>