父级项目

1.创建

 2.记住Group 与Artifact

 3.可勾选所需依赖或者不选

后期根据所需要再添加

 4.命名

5.删除主项目一些文件

 子级模块

 1.创建

 2.根据自己变更模块的名称

 3.创建成功

 需要再多的模块可按上面创建

配置

1.父级Pow文件配置

<?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>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.tinygray</groupId>
    <artifactId>multi-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>multi-parent</name>
    <description>Demo project for Spring Boot</description>
    <!--修改父项目的打包方式为pom-->
    <packaging>pom</packaging>
    <!--添加子模块到父项目-->
    <modules>
        <module>controller</module>
    </modules>
    <!--依赖版本统一管理-->
    <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-starter</artifactId>
        </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>
        </dependency>
        <dependency>
            <!--解决非web模块 test打包报错问题  1.4.2.RELEASE版本可以-->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
            <version>2.0.1.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

2.子级Pow文件配置

<?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>
    <artifactId>controller</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>controller</name>
    <description>Demo project for Spring Boot</description>
    <!--引入父项目 替换掉之前的springboot父项目(spring-boot-starter-parent)-->
    <parent>
        <artifactId>demo</artifactId>
        <groupId>com.tinygray</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
   <!-- <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
        <relativePath/> <!– lookup parent from repository –>
    </parent>-->
    <dependencies>
        <!--引入service模块-->
        <dependency>
            <groupId>com.demo</groupId>
            <artifactId>service</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.example.demo.DemoApplication</mainClass>
                    <layout>JAR</layout>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

运行

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐