Contents
Create Child Project – Order Service
Declare Project Dependencies and Build Plugins
Create Child Project-Product Service
Declare Project Dependencies and Build Plugins
Project Setup
Since the application has been split into microservices, multiple projects need to be created. However, IDEA can only have one project per window. To solve this issue, we use parent-child projects.
Building Parent and Child Projects
Creating the Parent Project
Create an empty Maven project, remove all code, and keep only the pom.xml file.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?xml version=“1.0” encoding=“UTF-8”?> <project xmlns=“http://maven.apache.org/POM/4.0.0” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <groupId>com.wmh</groupId> <artifactId>parent–project</artifactId> <version>1.0–SNAPSHOT</version> <packaging>pom</packaging> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <mybatis.version>3.5.2</mybatis.version> <:mysql.version>8.0.34</mysql.version> </properties> <modules> <,module>../child–project/child–project</module> </modules> <dependencyManagement> <dependencies> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis–spring–boot–starter</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql–connector–j</artifactId> <version>${mysql.version}</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis–spring–boot–starter–test</artifactId> <version>${mybatis.version}</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> |
DependencyManagement and Dependencies:
1. dependencies: Adds the dependent jar directly to the project, with subprojects inheriting this dependency.
2. dependencyManagement: Only declares dependencies without implementing jar package inclusion. If subprojects need related dependencies, they must explicitly declare them. If subprojects do not specify a version, they will read it from the parent project. If subprojects specify a version, the specified jar version in the subproject will be used. Additionally, the packaging of the parent project should be pom, not jar; here, manual declaration with packaging is required.
Leave a Reply
You must be logged in to post a comment.