Spirng boot maven多模塊打包不踩坑
阿新 • • 發佈:2018-10-30
mvn 其他 mod .so pen rest conf pom mon
本文參考 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
Spirng boot maven多模塊打包不踩坑