maven 三种打包插件 及 初识JFrog Artifactory
maven三种打包插件
maven有多种可以打包的插件,如下:
plugin | function | 官网 |
---|---|---|
maven-jar-plugin | maven 默认打包插件,用来创建 project jar | |
maven-shade-plugin | 用来打可执行包,executable(fat) jar | http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html |
maven-assembly-plugin | 支持定制化打包方式,例如 apache 项目的打包方式 | http://maven.apache.org/plugins/maven-assembly-plugin/usage.html |
我们主要是要打zip包,也就是要使用maven-assembly-plugin插件。
maven-assembly-plugin pom配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/main/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!--this is used for inheritance merges 绑定到这个生命周期-->
<goals>
<goal>single</goal> <!--执行一次-->
</goals>
</execution>
</executions>
</plugin>
指定打包文件 src/main/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>full</id>
<!--这个id会出现在zip包名称的后面,zip的完整名是:pom.xml中的artifactId-version-id.zip -->
<formats>
<!--支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war-->
<format>zip</format>
</formats>
<dependencySets>
<!-- 用来定制工程依赖 jar 包的打包方式,依赖包的输出路径 -->
<dependencySet>
<outputDirectory>/libs</outputDirectory> <!--依赖jar包的输出目录-->
<useProjectArtifact>false</useProjectArtifact>
<includes> <!--指定把哪些依赖包放进去 -->
<!--如果不指定 则所有的依赖都会打入,但是有的时候 我们只需要打特定依赖的包-->
<include>net.sf.jsi:jsi</include>
<include>net.sf.trove4j:trove4j</include>
</includes>
</dependencySet>
</dependencySets>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets><!--这里指定需要包含的其他文件-->
<fileSet>
<!--管理一组文件的存放位置-->
<outputDirectory>/</outputDirectory> <!--放在哪-->
<directory>target</directory><!--源目录-->
<includes>
<include>*.jar</include> <!--代码的jar包-->
</includes>
</fileSet>
<fileSet>
<outputDirectory>/shell</outputDirectory>
<directory>src/main/resources/shell</directory>
<includes>
<include>*/*.sh</include> <!--把shell脚本打进去-->
<include>*/*.conf</include> <!--把conf文件打进去-->
</includes>
</fileSet>
</fileSets>
</assembly>
这个xml的配置属性及其说明参见:http://gitlab.tenddata.com/data-process/gp-etl/blob/spark2.3test/src/main/package.xml
初识JFrog Artifactory
背景
在软件项目开发中,一个项目常常依赖于大量的外部库,而这些外部库又在不断的进行版本更新,特别是在当前微服务开发越来越流行的情况下,一个服务依赖于多个服务,如何管理依赖库以及依赖版本,确保开发有序进行呢?
JFrog ArtiFactory
ArtiFactory是一款二进制存储管理工具,用来管理构建工具(如:gradle)等所依赖的二进制仓库,以方便管理第三方库和发布目标版本库,从而提高软件开发效率。它提供大量的插件以利于和不同工具之间的整合,内部使用权限管理更加安全,并支持高并发等等特性。另外我们搭建Artifactory私服的原因还有:
私有仓库的目的是作为团队内所使用的所有软件构件的内部私有构件仓库,将Maven构件(jar和pom)存储到一个专门的Maven仓库比将它们存储到版本控制系统中更有优势,这是因为:
·构件(jar)是二进制文件,不属于git版本控制系统,后者在处理文本文件方面比较好
·减少可能的版本冲突
·减少首次构建时需要的手动干涉
·中央仓库包含所有依赖的软件构件,引用单一的中央仓库比引用多个独立的本地库要好
·使用内部仓库做clean构建时会快些,因为Maven构件是从内部服务器而不是从因特网上获取。
生态环境
报价
最少功能且无任何售后支持的报价为2950美元每年。
JFrog Artifactory开源版:
http://www.jfrogchina.com/open-source/
JFrog Artifactory企业版(免费试用):
https://www.jfrog.com/artifactory/free-trial/?lang=zh-hans#High-Availability
- 点赞
- 收藏
- 关注作者
评论(0)