maven-assembly-plugin配置打包
1、概述
maven-assembly-plugin打包可以把一些配置文件打包到jar包外面
2、添加pom依赖
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<!-- 打tar.gz包 -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-targz</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/../release/tar.gz</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
3、配置assembly.xml
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>release</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/script</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.sh</include>
<include>*.bat</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/target</directory>
<outputDirectory></outputDirectory>
<includes>
<include>springboot-12-assembly*.jar</include>
</includes>
</fileSet>
<!--devops仅用于开发和test环境, stage环境和线上环境会由部署系统自动生成devops并覆盖-->
<fileSet>
<directory>${project.basedir}/src/main/resources/devops</directory>
<outputDirectory>devops</outputDirectory>
<includes>
<include>*.properties</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<outputDirectory></outputDirectory>
<source>${project.basedir}/src/main/resources/application.properties</source>
<destName>application.properties</destName>
</file>
</files>
</assembly>
4、打包
方法一、idea中直接运行maven的package
方法二、命令
mvn clean package -Dmaven.test.skip=true -Pstage -s D:\mygit\SpringBoot-Learn\springboot-07-jpa\assembly.xml