DevOps进阶(九)使用assembly plugin实现自定义打包

举报
SHQ5785 发表于 2020/12/29 23:42:07 2020/12/29
5.6k+ 0 0
【摘要】 DevOps进阶(九)使用assembly plugin实现自定义打包 assembly plugin的使用方式比较简单,主要有:1. 修改pom.xml pom.xml中设置如下: <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</art...

DevOps进阶(九)使用assembly plugin实现自定义打包

assembly plugin的使用方式比较简单,主要有:

1. 修改pom.xml

pom.xml中设置如下:

<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <!-- not append assembly id in release file name --> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assemble/package.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

  
 

其中<artifactId>maven-assembly-plugin</artifactId>的maven-assembly-plugin是这个插件的标准命名,在maven2.0.*中带的默认版本。

appendAssemblyId属性控制是否在生成的打包文件的文件名中包含assembly id。

descriptor属性指定maven-assembly-plugin的配置文件,当然我设置的是src/main/assemble/package.xml.容许使用多个,功能强大当然用法也复杂,对于简单情况一个足矣。

execution的设置是为了将maven-assembly-plugin继承到标准的maven打包过程中,这样在运行maven-package时就会执行maven-assembly-plugin的操作,从而实现我们需要的自定义打包。
2. assemble descriptor file

我的src/main/assemble/package.xml内容如下:

   <assembly 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/assembly-1.0.0.xsd"> <id>package</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <fileSets> <fileSet> <directory>src/main/bin</directory> <outputDirectory>/</outputDirectory> </fileSet> <fileSet> <directory>src/main/config</directory> <outputDirectory>config</outputDirectory> </fileSet> </fileSets> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <scope>runtime</scope> </dependencySet> </dependencySets>
</assembly>

  
 

详细的语法不介绍了,请参考官方指南,有非常详尽的说明:Assembly
Descriptor Format reference


简单解释一下:

1) format
format=zip设置打包的最终文件格式为zip.
支持的其他格式还有gz,tar,tar.gz,tar.bz2。

  <fileSet> <directory>src/main/bin</directory> <outputDirectory>/</outputDirectory> </fileSet> 将src/main/bin目录下的文件打包到根目录(/)<fileSet> <directory>src/main/config</directory> <outputDirectory>config</outputDirectory>
</fileSet>
将src/main/config目录下的文件打包到config下. <fileSet> <directory>src/main/config</directory> <outputDirectory>config</outputDirectory>
</fileSet>

将scope为runtime的依赖包打包到lib目录下。
总结一下,pom.xml中引入maven-assembly-plugin,然后assemble descriptor file按需设置,最后在eclipse中执行`Run As Maven package`,在target目录下就会出现***.zip文件,里面的格式和要求的完全一致。

  
 

文章来源: shq5785.blog.csdn.net,作者:No Silver Bullet,版权归原作者所有,如需转载,请联系作者。

原文链接:shq5785.blog.csdn.net/article/details/84821580

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。