欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Maven 打包(瘦打包部署),不包含第三方依赖的 jar 包

最编程 2024-03-03 21:18:59
...
<properties>
<startClass>com.answer.jaemon.Application</startClass>
</properties>

<build>
<plugins>
<!-- 生成不包含依赖jar的可执行jar包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<!--
<goals>
<goal>repackage</goal>
</goals>
-->
<configuration>
<!-- 不加的话最终包名为: ${artifactId}-${version}.jar, 加了的话最终包名: ${artifactId}-${version}-${classifier}.jar -->
<classifier>execute</classifier>
<!-- 不指定生成路径的话, 默认保存在 ${build.directory} 下 -->
<outputDirectory>
${project.build.directory}/execute
</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<finalName>${artifactId}-${version}</finalName>
<layout>ZIP</layout>
<mainClass>${startClass}</mainClass>
<includes>
<include>
<groupId>bframe-parent</groupId>
<artifactId>bframe-aut-dao</artifactId>
</include>
</includes>
</configuration>
</plugin>

<!-- 拷贝依赖的jar包到lib目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- ${project.build.directory}是maven变量,内置的,表示target目录,如果不写,将在跟目录下创建/lib -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<!-- excludeTransitive:是否不包含间接依赖包,比如我们依赖A,但是A又依赖了B,我们是否也要把B打进去 默认不打-->
<excludeTransitive>false</excludeTransitive>
<!-- 复制的jar文件去掉版本信息 -->
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>

<!-- 设置源文件编码方式 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

<!-- 解决资源文件的编码问题 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>