本文参考 https://blog.csdn.net/Ser_Bad/article/details/78433340
经过实战一次通过。回话不多说,话费不多说,直接上图。
项目整体结构:
父模块:
<?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.quark</groupId> <artifactId>quark-parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <!--管理所有的模块--> <modules> <module>quark-admin</module> <module>quark-chat</module> <module>quark-common</module> <module>quark-portal</module> <module>quark-rest</module> </modules> <!-- 集中定义依赖版本号与基本配置 --> <properties> <!--指定jdk的版本为1.8,默认为1.6--> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencyManagement> <dependencies> 省略其他公共包 </dependencies> </dependencyManagement> <!--指定使用maven打包--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> <!--默认关掉单元测试 --> </configuration> </plugin> </plugins> </build> </project>
admin模块:
<?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> <!--指定父模块,需要注意的是,这里要指定父模块pom.xml的相对路径--> <parent> <artifactId>quark-parent</artifactId> <groupId>com.quark</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>com.quark</groupId> <artifactId>quark-admin</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <dependencies> 省略导包 </dependencies> <!--spring boot打包的话需要指定一个唯一的入门--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 指定该Main Class为全局的唯一入口 --> <mainClass>com.quark.admin.AdminApplication</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中--> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
其他模块都是一致的配置
如果有公共模块不需要打包
<?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"> <parent> <artifactId>quark-parent</artifactId> <groupId>com.quark</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.quark</groupId> <artifactId>quark-common</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> ........... </dependencies> </project>
打包
按照上面的配置好以后,执行下面的命令就好了
mvn clean package
上面的命令是打包所以,如果要单个打包用下面的命令
mvn -pl quark-admin -am install