Apache Maven Assembly Plugin使用记录

打包是开发、测试及发版不可避免的步骤,这里对assembly使用过程中遇到的问题做下记录。

1.pom引入plugin依赖

profile中properties的属性声明将其与assembly结合起来,不同环境使用不同配置文件

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <env.devMode>dev</env.devMode>
                <skipAssemblyDEV>false</skipAssemblyDEV>
                <skipAssemblyUAT>true</skipAssemblyUAT>
                <skipAssemblyPROD>true</skipAssemblyPROD>
            </properties>
        </profile>
        <profile>
            <id>uat</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <env.devMode>uat</env.devMode>
                <skipAssemblyDEV>true</skipAssemblyDEV>
                <skipAssemblyUAT>false</skipAssemblyUAT>
                <skipAssemblyPROD>true</skipAssemblyPROD>
            </properties>
        </profile>
    </profiles>
    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>make-assembly-dev</id>  
                        <phase>package</phase> 
                        <goals>
                            <goal>single</goal>                        </goals>
                        <configuration>
                            <skipAssembly>${skipAssemblyDEV}</skipAssembly>
                            <descriptors>
                                <descriptor>src/main/assembly/dev/assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>make-assembly-uat</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <skipAssembly>${skipAssemblyUAT}</skipAssembly> 
                            <descriptors>
                                <descriptor>src/main/assembly/uat/assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>make-assembly-prod</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <skipAssembly>${skipAssemblyPROD}</skipAssembly>
                            <descriptors>
                                <descriptor>src/main/assembly/prod/assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    </plugins>

2.目录项目路劲配置变化

2.5.4以上版本使用时,fileSet标签下的outputDirectory不能再使用/作为开始的字符表示输出的相对目录了,可以使用点表示当前目录

<fileSet>
            <directory>src/main/resources</directory>
            <outputDirectory>.</outputDirectory>
</fileSet>

3.覆盖特点

使用Assembly时,fileSet顺序决定最终打包进去的文件,前面的fileSet如果已经放置了同名文件,后面的fileSet不会覆盖。

下面的配置示例中,最终打包中的a.txt包含的是prod内容。

<fileSet>
            <directory>src/main/resources/prod</directory>  <!-- 此目录文件a.txt中记录为prod内容 -->
            <outputDirectory>.</outputDirectory>
            
</fileSet>
<fileSet>
            <directory>src/main/resources</directory><!-- 此目录文件a.txt中记录为默认测试内容 -->
            <outputDirectory>.</outputDirectory>
            <excludes>
                <exclude>prod/**/*<exclude>
            </excludes>
</fileSet>

这里放上官网传送门Apache Maven Assembly Plugin – Introduction

 这里也有一个参考文章,https://www.cnblogs.com/lianshan/p/7348093.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值