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:
- 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>
- 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>
- childA:
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>
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot