maven-assembly-plugin dependencySet 打包多出额外的依赖包

pom和插件配置

pom.xml

<build>
	<plugins>
		<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <includes>
                    <include>
                        <groupId>not.exists.groupId</groupId>
                        <artifactId>not.exists.artifactId</artifactId>
                    </include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <id>default</id>
                    <phase>package</phase>
                    <configuration>
                        <classifier>bootapp</classifier>
                    </configuration>
                    <goals>
                        <goal>build-info</goal>
                        <goal>repackage</goal>
                    </goals>
                </execution>
                <dependencies>
                   <dependency>
                       <groupId>github.clyoudu.com</groupId>
                       <artifactId>spring-boot-thin-layout</artifactId>
                       <version>1.0.0</version>
                   </dependency>
               </dependencies>
            </executions>
        </plugin>
		<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/assembly.xml</descriptor>
                </descriptors>
                <outputDirectory>target</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

assembly.xml

<?xml version='1.0' encoding='UTF-8'?>
<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>bin</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>true</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${project.basedir}/src/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <includes>
                <include>*.sh</include>
            </includes>
            <lineEnding>unix</lineEnding>
            <fileMode>0755</fileMode>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>main</outputDirectory>
            <includes>
                <include>*-bootapp.jar</include>
            </includes>
        </fileSet>
    </fileSets>
	<dependencySets>
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
			<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
        </dependencySet>
</assembly>

打包逻辑:

  1. 使用spring-boot-maven-plugin打出可执行jar,但排除了所有依赖(not.exists.groupId不会将任何依赖包打入fatjar),通过自定义的spring-boot-thin-layout扩展spring-boot-maven-plugin,使其生成的可执行jar能够按照maven依赖顺序加载jar包外部的依赖;
  2. 使用assembly-maven-plugin将启动脚本、启动jar、依赖包分别放入不同的目录,最后打包成tar.gz

问题

打包完成后,发现lib目录多出了几个依赖,这些依赖没有主动引入的痕迹,并且使用maven helpermaven-dependency-plugin等工具都找不到引入的路径

解决

最后找到这篇文章:maven-assembly-plugin 打包包含多余依赖问题一则

你在pom对某个坐标使用exclusion *,排除全部传递依赖的时候,老版本的maven-assembly-plugin插件依然会包含 大专栏 maven-assembly-plugin 打包包含多余依赖问题一则你已经排除的依赖。

果然,在没有指定maven-assembly-plugin版本时,默认版本为3.1.0,指定版本为3.1.1后该问题解决。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值