转载

SpringBoot多模块项目搭建(一)

SpringBoot多模块项目搭建(一)

1.2 设置groupId和artifactId

SpringBoot多模块项目搭建(一)

1.3 设置项目名

SpringBoot多模块项目搭建(一)

1.4 删除源码目录

2. 新建应用程序入口模块

2.1 右击项目,新建Springboot module

SpringBoot多模块项目搭建(一)

2.2 设置groupId和artifactId

SpringBoot多模块项目搭建(一)

2.3 选择需要的依赖(后续引入也行) 建议引入SpringBoot DevTools、Lombok、Spring web 2.4 设置module路径,finish

3. 修改root项目pom.xml

3.1 添加modules,并声明各个module

<modules>
    <module>springboot-base</module>
</modules>
复制代码

3.2 添加properties,用于配置各种依赖的版本号等其它配置项

<properties>
    <springboot-base-version>1.0-SNAPSHOT</springboot-base-version>
    <spring.boot.version>2.2.0.RELEASE</spring.boot.version>
</properties>
复制代码

3.3 添加dependencyManagement,用于管理各个jar的引入

此时,root项目的pom.xml文件如下

<?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.jw</groupId>
    <artifactId>springboot-base-root</artifactId>
    <version>${springboot-base-version}</version>

    <modules>
        <module>springboot-base</module>
    </modules>

    <properties>
        <springboot-base-version>1.0-SNAPSHOT</springboot-base-version>
        <spring.boot.version>2.2.0.RELEASE</spring.boot.version>
    </properties>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>${spring.boot.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <version>${spring.boot.version}</version>
                <scope>runtime</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${spring.boot.version}</version>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <version>${spring.boot.version}</version>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>
复制代码

4. 修改各个子模块的pom.xml

4.1 修改parent为root模块

4.2 修改当前module的version与父模块一致

此时pom.xml文件如下

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>com.jw</groupId>
		<artifactId>springboot-base-root</artifactId>
		<version>${springboot-base-version}</version>
	</parent>

	<groupId>com.jw</groupId>
	<artifactId>springboot-base</artifactId>
	<version>${springboot-base-version}</version>
	<name>springboot-base</name>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>
复制代码
原文  https://juejin.im/post/5dbd3637f265da4cef19084d
正文到此结束
Loading...