本文为博主原创,转载请注明出处:

目录:

  1. maven-release-plugin

  2. maven-compiler-plugin

  3. maven-assembly-plugin

  4. spring-boot-maven-plugin

  5. maven-resources-plugin

  6. maven-dependency-plugin

1.maven -release-plugin

  提供自动化发布功能,自动升级版本,并将代码提交git服务器

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tagBase>http://git.spt.com/team/supply.git</tagBase>
<connectionUrl>http://git.spt.com/team/supply.git</connectionUrl>
<useReleaseProfile>false</useReleaseProfile>
<autoVersionSubmodules>true</autoVersionSubmodules>
<preparationGoals>clean deploy</preparationGoals>
   <!--git用户名-->
<username>xxxxx@aikucun.com</username>
<!--git密码-->
<password>xxxx</password>
</configuration>
</plugin>

2.maven-compiler-plugin

  指定maven 编译的jdk 版本及编译时的配置。以下为简约配置。通过指定maven 中jdk 编译的版本,可以避免代码工具的jdk 版本变更后,项目编译出现问题

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<!-- 一般而言,target与source是保持一致 -->
<source>1.8</source> <!-- 源代码使用的JDK版本 -->
<target>1.8</target> <!-- 需要生成的目标class文件的编译版本 -->
<encoding>UTF-8</encoding><!-- 字符集编码,防止中文乱码 -->
<skipTests>true</skipTests><!-- 跳过测试 -->
<verbose>true</verbose>
<showWarnings>true</showWarnings>
</configuration>
</plugin>

3.maven-assembly-plugin

  在Maven中,主要有3个插件可以用来打包:  

      • maven-jar-plugin,默认的打包插件,用来打普通的project JAR包;
      • maven-shade-plugin,用来打可执行JAR包,也就是所谓的fat JAR包;
      • maven-assembly-plugin,支持自定义的打包结构,也可以定制依赖项等。

  我们日常使用的以maven-assembly-plugin为最多,因为大数据项目中往往有很多shell脚本、SQL脚本、.properties及.xml配置项等,采用assembly插件可以让输出的结构清晰而标准化。

  示例:

    <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}<version>
<executions>
<execution>
<id>make-assembly</id>
<!-- 绑定到package生命周期 -->
<phase>package</phase>
<goals>
<!-- 只运行一次 -->
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 配置描述符文件 -->
<descriptor>src/main/assembly/assembly.xml</descriptor>
<!-- 也可以使用Maven预配置的描述符
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs> -->
</configuration>
</plugin>
</plugins>
</build>

  assembly插件的打包方式是通过descriptor(描述符)来定义的。
  Maven预先定义好的描述符有bin,src,project,jar-with-dependencies等。比较常用的是jar-with-dependencies,它是将所有外部依赖JAR都加入生成的JAR包中,比较傻瓜化。
但要真正达到自定义打包的效果,就需要自己写描述符文件,格式为XML。下面是我们的项目中常用的一种配置。

<assembly>
<id>assembly</id> <formats>
<format>tar.gz</format>
</formats> <includeBaseDirectory>true</includeBaseDirectory> <fileSets>
<fileSet>
<directory>src/main/bin</directory>
<includes>
<include>*.sh</include>
</includes>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>src/main/conf</directory>
<outputDirectory>conf</outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/sql</directory>
<includes>
<include>*.sql</include>
</includes>
<outputDirectory>sql</outputDirectory>
</fileSet>
<fileSet>
<directory>target/classes/</directory>
<includes>
<include>*.properties</include>
<include>*.xml</include>
<include>*.txt</include>
</includes>
<outputDirectory>conf</outputDirectory>
</fileSet>
</fileSets> <files>
<file>
<source>target/${project.artifactId}-${project.version}.jar</source>
<outputDirectory>.</outputDirectory>
</file>
</files> <dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>

  id与formats

    formats是assembly插件支持的打包文件格式,有zip、tar、tar.gz、tar.bz2、jar、war。可以同时定义多个format。
    id则是添加到打包文件名的标识符,用来做后缀。
    也就是说,如果按上面的配置,生成的文件就是 a r t i f a c t I d − {artifactId}-artifactId−{version}-assembly.tar.gz。

  fileSets/fileSet
    用来设置一组文件在打包时的属性。

  directory:源目录的路径。
  includes/excludes:设定包含或排除哪些文件,支持通配符。
  fileMode:指定该目录下的文件属性,采用Unix八进制描述法,默认值是0644。
  outputDirectory:生成目录的路径。

  files/file

    与fileSets大致相同,不过是指定单个文件,并且还可以通过destName属性来设置与源文件不同的名称。
  dependencySets/dependencySet
    用来设置工程依赖文件在打包时的属性。也与fileSets大致相同,不过还有两个特殊的配置:

  unpack:布尔值,false表示将依赖以原来的JAR形式打包,true则表示将依赖解成*.class文件的目录结构打包。
  scope:表示符合哪个作用范围的依赖会被打包进去。compile与provided都不用管,一般是写runtime。

  按照以上配置打包好后,将.tar.gz文件上传到服务器,解压之后就会得到bin、conf、lib等规范化的目录结构,十分方便。

4.spring-boot-maven-plugin

  能够以Maven的方式为应用提供Spring Boot的支持,即为Spring Boot应用提供了执行Maven操作的可能。

   Spring Boot Maven plugin的5个Goals

  • spring-boot:repackage,默认goal。在mvn package之后,再次打包可执行的jar/war,同时保留mvn package生成的jar/war为.origin
  • spring-boot:run,运行Spring Boot应用
  • spring-boot:start,在mvn integration-test阶段,进行Spring Boot应用生命周期的管理
  • spring-boot:stop,在mvn integration-test阶段,进行Spring Boot应用生命周期的管理
  • spring-boot:build-info,生成Actuator使用的构建信息文件build-info.properties

    配置pom.xml文件

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

  使用该插件打包之后,会生成一个 以 original 的软件包:

5. maven-resources-plugin

    Resources插件负责处理项目资源文件并拷贝到输出目录。Maven将main resources和test resources分开,一般main resources关联main source code,而test resources关联test source code。

   Resources插件目标有三个:

  1. resources:resources,拷贝main resources到main output directory。它绑定了process-resources生命周期阶段,当执行Compiler:compile插件目标前就会执行此阶段。
  2. resources:testResources,拷贝test resources到test output directory。它绑定了process-test-resources生命周期阶段,当执行surefire:test插件目标前就会执行此阶段。
  3. resources:copy-resources,手动拷贝资源到输出目录

  pom 简约配置示例: 

<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>

  可能用到的配置:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<!-- 一个execution就是一个目标输入位置,如果想把各种资源拆开放的话,就
可以创建多个execution,一个资源文件可以被拷贝多份 -->
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<!-- 资源文件的输出目录 -->
<outputDirectory>{project.build.directory}/config</outputDirectory>
<resources>
<!-- 资源文件的原始目录,有多个的话就多配几个 -->
<resource>
<!-- 原始目录 -->
<directory>src/main/resources</directory>
<!-- 是否使用过滤器,如果是的话,需要配置一下才行
这个后续再研究,这边没有使用到 -->
<filtering>true</filtering>
<!-- 包含哪些文件以及去除调哪些文件等等 -->
<includes>
<include>**/*.*</include>
</includes>
<excludes>
<exclude>**/*.json</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

6. maven-dependency-plugin

  用来拷贝项目所有依赖,可能会用到的一些配置如下:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 拷贝项目依赖包到lib/目录下 -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<!-- 间接依赖也拷贝 -->
<excludeTransitive>false</excludeTransitive>
<!-- 带上版本号 -->
<stripVersion>false</stripVersion>
</configuration>
</execution>
</executions>
</plugin>

maven总结三: 常用插件的更多相关文章

  1. (三)Maven基本概念——常用插件的配置

    看注释———— pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http ...

  2. maven入门与常用插件使用

    maven不仅仅是一款管理jar包的工具,还可以

  3. 【编程工具】Sublime Text3的安装和常用插件推荐

    本人刚刚学习 HTML,曾经上网找过一些编写 HTML 的软件,但感觉都不太好,经过三挑四选下,最终我决定选择 Sublime Text3 这款软件来作为学习工具,上网找到了许多实用的插件,在这里给大 ...

  4. maven常用插件配置详解

    常用插件配置详解Java代码    <!-- 全局属性配置 --> <properties> <project.build.name>tools</proje ...

  5. (六)maven之常用插件

    一.maven的插件 maven官方插件:http://maven.apache.org/plugins/index.html 二.常用插件之:javadoc 作用:生成代码文档 2.1 编写代码,并 ...

  6. Maven常用插件

    maven利用各种插件来管理构建项目,本文记录下工作中常用到的插件及使用方法.每个插件都会提供多个目标(goal),用于标示任务.各插件配置在pom.xml里,如下: <build> [. ...

  7. maven常用插件pom配置

    一.问题描述: 部署一个maven打包项目时,jar包,依赖lib包全部手动上传至服务器,然后用maven部署报错:Exception in thread "main" java. ...

  8. maven常用插件总结

    maven本质上是一个插件框架,几乎所有的功能都是通过各种各样的插件来实现的.maven默认会依据项目类型自动把构建时的各阶段(Lifecycle和phase)自动绑定(Lifecycle Mappi ...

  9. Maven系列学习(三)Maven生命周期和插件

    Maven生命周期和插件 Maven另外的两个核心概念就是生命周期和插件,Maven的生命周期都是抽象的,其实实际行为都是由插件来完成的,生命周期和插件两者协同工作 1.生命周期 Maven的生命周期 ...

  10. maven 常用插件总结

    maven-javadoc-plugin (1) 说明:该插件生成项目的javadoc.对于构建jar目标,javadoc会首先生成并打包放入jar文件中. (2) 默认用法: pom.xml配置 & ...

随机推荐

  1. [CSP-S 2023] 密码锁

    题目描述 小 Y 有一把五个拨圈的密码锁.如图所示,每个拨圈上是从 \(0\) 到 \(9\) 的数字.每个拨圈都是从 \(0\) 到 \(9\) 的循环,即 \(9\) 拨动一个位置后可以变成 \( ...

  2. hszxoj 矿场搭建 [tarjan]

    hszxoj 矿场搭建 题目描述 原题来自:HNOI 2012 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决 ...

  3. 三维GIS渲染引擎盘点,以Cesium为核心的拓展优化

    目前,以Cesium为核心的各类产品繁多,本文将挑选一些以Cesium为核心的软件案例,为大家进行介绍. 1. CesiumJS CesiumJS相信凡是GIS行业相关人员都特别熟悉了,CesiumJ ...

  4. 【并发编程特性】并发编程特性之五种特性的探讨-volatileandsynchronized

    title: [并发编程特性]并发编程特性之五种特性的探讨 date: 2021-11-18 10:16:05.492 updated: 2021-12-26 17:43:10.414 url: ht ...

  5. OpenFeign:Spring Cloud声明式服务调用组件

    OpenFeign:Spring Cloud声明式服务调用组件 问题总结 OpenFeign? Feign VS OpenFeign? OpenFeign实现远程服务调用? OpenFeign超时控制 ...

  6. 劫持最新版 QQNT / QQ / TIM 客户端 ClientKeys

    针对 腾讯官网 最新发布的 QQNT 9.9.6 与 QQ 9.7.21 新版本客户端全面更新截取代码 大伙应该都知道自从 QQ 9.7.20 版本起就已经不能通过模拟网页快捷登录来截取 Uin 跟 ...

  7. Tailscale 基础教程:Headscale 的部署方法和使用教程

    Tailscale 是一种基于 WireGuard 的虚拟组网工具,它在用户态实现了 WireGuard 协议,相比于内核态 WireGuard 性能会有所损失,但在功能和易用性上下了很大功夫: 开箱 ...

  8. mysql 数据库 定时 备份到阿里云盘

    仓库地址: gitee:db_backup_script: mysql 数据库 定时/实时 备份数据库到阿里云盘,备份成功后消息可通知到钉钉群.企业微信群.wxpusher (gitee.com gi ...

  9. Langchain-Chatchat项目:2.1-通过GPT2模型来检索NebulaGraph

      在官方例子中给出了通过chain = NebulaGraphQAChain.from_llm(ChatOpenAI(temperature=0), graph=graph, verbose=Tru ...

  10. 神经网络基础篇:史上最详细_详解计算图(Computation Graph)

    计算图 可以说,一个神经网络的计算,都是按照前向或反向传播过程组织的.首先计算出一个新的网络的输出(前向过程),紧接着进行一个反向传输操作.后者用来计算出对应的梯度或导数.计算图解释了为什么用这种方式 ...