Help Center/ CodeArts Build/ FAQs/ Maven Builds/ How Do I Fix the Errors Related to References Among Multiple Child and Parent Projects?
Updated on 2024-10-10 GMT+08:00

How Do I Fix the Errors Related to References Among Multiple Child and Parent Projects?

Symptoms

In Maven build task, the POM file contains multiple references between child and parent projects. During task execution, the following error information is recorded in logs:

[ERROR] Project 'xxx.xxx:xxx1:1.0-SNAPSHOT' is duplicated in the reactor @
[2022-03-02 14:02:52.656] [ERROR] Project 'xxx.xxx:xxx2:1.0-SNAPSHOT' is duplicated in the reactor -> [Help 1]
[2022-03-02 14:02:52.656] [ERROR]
[2022-03-02 14:02:52.656] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[2022-03-02 14:02:52.656] [ERROR] Re-run Maven using the -X switch to enable full debug logging.

Cause Analysis

In Maven, the parent can specify its modules, such as childA and childB. This is called aggregation. To compile multiple modules together, perform the following steps:

  1. Add the following configurations to the parent POM:
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>
    <modules>
       <module>childA</module>
       <module>childB</module>
    </modules>
  2. Add the following configurations to the childA POM and childB POM to specify their parent:
    • childA:
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.demo</groupId>
      <artifactId>childA</artifactId>
      <version>1.0</version>
      <parent>
         <groupId>com.demo</groupId>
         <artifactId>parent</artifactId>
         <version>1.0</version>
      </parent>
    • childB:
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.demo</groupId>
      <artifactId>childB</artifactId>
      <version>1.0</version>
      <parent>
         <groupId>com.demo</groupId>
         <artifactId>parent</artifactId>
         <version>1.0</version>
      </parent>

In these configurations, a parent project is specified for same-level children, childA and childB. The error shown at the beginning is displayed because a conflict occurs when childA POM references project B as its child or takes the parent project as its child.

Solution

Check the POM references of the projects. If you want project B to be a child project A, remove the reference of project B from the parent POM and point the parent tag of project B to project A.

  • Parent project:
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>
    <modules>
       <module>childA</module>
    </modules>
  • Project A:
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo</groupId>
    <artifactId>childA</artifactId>
    <version>1.0</version>
    <parent>
       <groupId>com.demo</groupId>
       <artifactId>parent</artifactId>
       <version>1.0</version>
    </parent>
    <modules>
       <module>childB</module>
    </modules>
  • Project B:
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo</groupId>
    <artifactId>childA</artifactId>
    <version>1.0</version>
    <parent>
       <groupId>com.demo</groupId>
       <artifactId>childA</artifactId>
       <version>1.0</version>
    </parent>