当前位置: 首页 > news >正文

maven 包管理平台-07-plugins 常见插件介绍

拓展阅读

maven 包管理平台-01-maven 入门介绍 + Maven、Gradle、Ant、Ivy、Bazel 和 SBT 的详细对比表格

maven 包管理平台-02-windows 安装配置 + mac 安装配置

maven 包管理平台-03-maven project maven 项目的创建入门

maven 包管理平台-04-maven archetype 项目原型

maven 包管理平台-05-multi module 多模块

maven 包管理平台-06-常用技巧 实时更新快照/乱码问题/下载很慢/包依赖解决包冲突/如何导入本地 jar

maven 包管理平台-07-plugins 常见插件介绍

maven 包管理平台-08-nexus 自己搭建 maven 仓库

maven 插件

Maven 在其核心是一个插件执行框架;所有工作都由插件完成。

寻找要执行的特定目标吗?此页面列出了核心插件和其他插件。

有构建和报告插件:

  • 构建(Build) 插件将在构建过程中执行,它们应该在 POM 中的 <build/> 元素中进行配置。

  • 报告(Reporting) 插件将在站点生成期间执行,它们应该在 POM 中的 <reporting/> 元素中进行配置。因为报告插件的结果是生成站点的一部分,所以报告插件应该同时进行国际化和本地化。您可以关于插件本地化的信息以及您可以如何帮助的内容。

Maven 插件

核心插件

这些插件对应于默认的核心阶段(即 clean,compile 等)。

它们也可能有多个目标。

compiler

编译 Java 源代码。

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>1.8</source><target>1.8</target></configuration>
</plugin>

surefire

在隔离的类加载器中运行 JUnit 单元测试。

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${maven-surefire-plugin.version}</version><configuration><skipTests>true</skipTests><testFailureIgnore>true</testFailureIgnore></configuration>
</plugin>

报告插件

生成报告的插件,在 POM 中配置为报告,并在站点生成生命周期下运行。

javadoc

为项目生成 Javadoc 文档。

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>2.9.1</version><configuration><!--maven 多模块--><aggregate>true</aggregate><!--路径--><reportOutputDirectory>../doc</reportOutputDirectory><!--目录--><destDir>myapidocs</destDir><!--IOS ERROR: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.--><javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable><!--自定义标签--><tags><tag><!--name为你Java代码中的注解的名字--><name>Description</name><!--事实上这个就是说你要把哪些(方法、字段、类)上面的注解放到JavaDoc中--><placement>a</placement><!--head。假设不写这个,用的就是name,假设写了,那么显示效果例如以下:--><head>用途</head></tag></tags></configuration></plugin>

其他

许多其他项目提供了它们自己的 Maven 插件。

tomcat7

运行 Apache Tomcat 容器以进行快速 Web 应用程序开发。

<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>${plugin.tomcat.version}</version><configuration><port>8081</port><path>/</path><uriEncoding>${project.build.sourceEncoding}</uriEncoding></configuration></plugin></plugins>
</build>

Versions

versions-plugin zh_CN

mvn versions:set -DnewVersion=1.0.1-SNAPSHOT
  • commit
mvn versions:commit
  • revert
mvn versions:revert

正确修改方法:

(1) 修改父类

mvn versions:set -DgroupId=com.framework -DartifactId=framework* -DoldVersion=* -DnewVersion=1.0.2-SNAPSHOT

(2) 修改子类

mvn -N versions:update-child-modules

Auto-Config

Auto-Config

简单案例

Import in maven

<?xml version="1.0" encoding="UTF-8"?>
<project 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/maven-v4_0_0.xsd"><properties><!-- 定义autoconfig的版本,建议将此行写在parent pom.xml中。 --><autoconfig-plugin-version>1.2</autoconfig-plugin-version></properties><build><plugins><plugin><groupId>com.alibaba.citrus.tool</groupId><artifactId>autoconfig-maven-plugin</artifactId><version>${autoconfig-plugin-version}</version><configuration><!-- 要进行AutoConfig的目标文件,默认为${project.artifact.file}。<dest>${project.artifact.file}</dest>--><!-- 配置后,是否展开目标文件,默认为false,不展开。<exploding>true</exploding>--><!-- 展开到指定目录,默认为${project.build.directory}/${project.build.finalName}。<explodedDirectory>${project.build.directory}/${project.build.finalName}</explodedDirectory>--></configuration><executions><execution><phase>package</phase><goals><goal>autoconfig</goal></goals></execution></executions></plugin></plugins></build>
</project>

跳过执行

$   mvn install –Dautoconfig.skip
  • 想使用配置文件

(1) 直接将生成的配置文件 antx.properties 视为配置文件使用。放在本地。 (2) 打成war包之后可以自动属性替换掉。

1、 maven war struct:

war-project(源目录结构)               -> war-project.war(目标目录结构)│  pom.xml│└─src└─main├─java├─resources                    -> /WEB-INF/classes│      file1.xml                      file1.xml│      file2.xml                      file2.xml│└─webapp                       -> /├─META-INF                 -> /META-INF│  └─autoconf              -> /META-INF/autoconf│        auto-config.xml          auto-config.xml│└─WEB-INF                  -> /WEB-INFweb.xml                     web.xmlfile3.xml                   file3.xml
  • /META-INF/autoconf 目录用来存放AutoConfig的描述文件,以及可选的模板文件。

  • auto-config.xml 是用来指导AutoConfig行为的关键描述文件。

2、 maven jar struct

jar-project(源目录结构)               -> jar-project.jar(目标目录结构)│  pom.xml│└─src└─main├─java└─resources                    -> /│  file1.xml                      file1.xml│  file2.xml                      file2.xml│└─META-INF                 -> /META-INF└─autoconf             -> /META-INF/autoconfauto-config.xml         auto-config.xml

3、Common directory

directory│  file1.xml│  file2.xml│└─confauto-config.xml

auto-config

<?xml version="1.0" encoding="UTF-8"?>
<config><group><property name="petstore.work"description="应用程序的工作目录" /><property name="petstore.loggingRoot"defaultValue="${petstore.work}/logs"description="日志文件目录" /><property name="petstore.upload"defaultValue="${petstore.work}/upload"description="上传文件的目录" /><property name="petstore.loggingLevel"defaultValue="warn"description="日志文件级别"><validator name="choice"choice="trace, debug, info, warn, error" /></property></group><script><generate template="WEB-INF/web.xml" /><generate template="WEB-INF/common/resources.xml" /></script>
</config>

完整的properties

<propertyname="..."[defaultValue="..."][description="..."][required="true|false"]
><validator name="..." /><validator name="..." />...
</property>

生成配置文件的指令

<generatetemplate="..."[destfile="..."][charset="..."][outputCharset="..."]
>

auto-config 命令

$ autoconfig
Detected system charset encoding: UTF-8
If your can't read the following text, specify correct one like this:autoconfig -c mycharset使用方法:autoconfig [可选参数] [目录名|包文件名]可选参数:-c,--charset                输入/输出编码字符集-d,--include-descriptors包含哪些配置描述文件,例如:conf/auto-config.xml,可使用*、**、?通配符,如有多项,用逗号分隔-D,--exclude-descriptors    排除哪些配置描述文件,可使用*、**、?通配符,如有多项,用逗号分隔-g,--gui                    图形用户界面(交互模式)-h,--help                   显示帮助信息-i,--interactive            交互模式:auto|on|off,默认为auto,无参数表示on-I,--non-interactive        非交互模式,相当于--interactive=off-n,--shared-props-name      共享的属性文件的名称-o,--output                 输出文件名或目录名-P,--exclude-packages       排除哪些打包文件,可使用*、**、?通配符,如有多项,用逗号分隔-p,--include-packages包含哪些打包文件,例如:target/*.war,可使用*、**、?通配符,如有多项,用逗号分隔-s,--shared-props           共享的属性文件URL列表,以逗号分隔-T,--type                   文件类型,例如:war, jar, ear等-t,--text                   文本用户界面(交互模式)-u,--userprop               用户属性文件-v,--verbose                显示更多信息

可执行 jar

  • xml 引入
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><version>2.5.5</version><configuration><archive><manifest><mainClass>com.xxg.Main</mainClass></manifest></archive><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions>
</plugin>
  • 命令行执行
$   mvn package

本文由博客一文多发平台 OpenWrite 发布!

相关文章:

  • Java 简历优化及注意事项
  • AI数据分析软件-BeepBI的诞生结束了传统BI时代,引领了数据分析零门槛的时代
  • 数据库原理实验课(1)
  • C#高级:Winform桌面开发中DataGridView的详解
  • Go语言必知必会100问题-16 不使用 linter
  • 入门了解huggingface实现ALBERT模型相关任务--Token Classification
  • 一条SQL引起的系统不可用
  • 前端性能优化的几个要点
  • 洛谷B2027题解
  • unicloud where 使用
  • 每日OJ题_链表④_力扣23. 合并 K 个升序链表(小根堆_归并)
  • 2024-3-8 python管理有序序列使用bisect模块,存放数字array比list更快更省空间
  • freeRTOS20240308
  • 【随手记】SQL语句中的COALESEC和IFNULL函数
  • 宠物空气净化器值得入手吗?选购宠物空气净化器关注哪些方面?
  • 「面试题」如何实现一个圣杯布局?
  • 【css3】浏览器内核及其兼容性
  • 10个确保微服务与容器安全的最佳实践
  • 2018一半小结一波
  • DOM的那些事
  • Hibernate【inverse和cascade属性】知识要点
  • javascript 总结(常用工具类的封装)
  • leetcode-27. Remove Element
  • Vue 2.3、2.4 知识点小结
  • 案例分享〡三拾众筹持续交付开发流程支撑创新业务
  • 正则学习笔记
  • 新年再起“裁员潮”,“钢铁侠”马斯克要一举裁掉SpaceX 600余名员工 ...
  • ​html.parser --- 简单的 HTML 和 XHTML 解析器​
  • ​iOS实时查看App运行日志
  • ​LeetCode解法汇总307. 区域和检索 - 数组可修改
  • #常见电池型号介绍 常见电池尺寸是多少【详解】
  • #我与Java虚拟机的故事#连载06:收获颇多的经典之作
  • (poj1.2.1)1970(筛选法模拟)
  • (vue)el-checkbox 实现展示区分 label 和 value(展示值与选中获取值需不同)
  • (超简单)使用vuepress搭建自己的博客并部署到github pages上
  • (附源码)基于SpringBoot和Vue的厨到家服务平台的设计与实现 毕业设计 063133
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理 第13章 项目资源管理(七)
  • (深度全面解析)ChatGPT的重大更新给创业者带来了哪些红利机会
  • (十八)三元表达式和列表解析
  • (算法)前K大的和
  • (小白学Java)Java简介和基本配置
  • (轉貼) 資訊相關科系畢業的學生,未來會是什麼樣子?(Misc)
  • *上位机的定义
  • .Net - 类的介绍
  • .net 后台导出excel ,word
  • .net经典笔试题
  • .NET中统一的存储过程调用方法(收藏)
  • .skip() 和 .only() 的使用
  • @serverendpoint注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)
  • [100天算法】-二叉树剪枝(day 48)
  • [AIGC] Spring Interceptor 拦截器详解
  • [Android]通过PhoneLookup读取所有电话号码
  • [BUG] Authentication Error
  • [BUUCTF]-PWN:[极客大挑战 2019]Not Bad解析
  • [BZOJ 3680]吊打XXX(模拟退火)