项目大体结构如下
项目
spring boot项目通用模块 SpringBase
项目基础模块 ProjectCommon
各个任务逻辑模块 A B C ...
上文建立项目中 删除除了pom.xml以外所有文件 并更新pom.xml
<groupId>com.mycompany</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>MyProject</name>
<description>Starter project for MyProject</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
<module>SpringBootCommon</module>
<module>MyProjectCommon</module>
<module>MyProjectModuleA</module>
</modules>
<!--指定项目中公有的模块-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>SpringBootCommon</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>MyProjectCommon</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
MyProject 项目右键 maven new maven module project
依次建立3个子模块
<module>SpringBootCommon</module>
<module>MyProjectCommon</module>
<module>MyProjectModuleA</module>
SpringBootCommon pom 如下
<parent>
<groupId>com.mycompany</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>SpringBootCommon</artifactId>
<name>SpringBootCommon</name>
<description>Spring Boot Starter</description>
MyProjectCommon pom 如下
<parent>
<groupId>com.mycompany</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>MyProjectCommon</artifactId>
<name>MyProjectCommon</name>
<description>My project Common</description>
MyProjectModuleA pom 如下
<parent>
<groupId>com.mycompany</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>MyProjectModuleA</artifactId>
<name>MyProjectModuleA</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>SpringBootCommon</artifactId>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>MyProjectCommon</artifactId>
</dependency>
</dependencies>
<!--spring boot打包的话需要指定一个唯一的入门-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.2.RELEASE</version>
<configuration>
<!-- 指定该Main Class为全局的唯一入口 -->
<mainClass>com.mycompany.StartApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
最后对项目外壳进行mvn package即可生成各模块jar
注意 项目外壳不要写maven build内容
哪个模块需要打包哪个模块写maven build插件