Guide to the Core Maven Plugins – 核心Maven插件指南

最后修改: 2018年 4月 19日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

Maven is the most commonly used build tool in the Java world. Mainly, it’s just a plugin execution framework in which all jobs are implemented by plugins.

Maven是Java世界中最常用的构建工具。主要而言,它只是一个插件执行框架,其中所有工作都由插件实现。

In this tutorial, we’ll give an introduction to the core Maven plugins, providing links to other tutorials focusing on what these plugins can do and how their goals are bound to the build lifecycles.

在本教程中,我们将介绍Maven的核心插件,提供其他教程的链接,重点介绍这些插件能做什么,以及它们的目标如何与构建生命周期绑定。

2. Maven Build Lifecycles

2.Maven的构建生命周期

Core plugins closely relate to the build lifecycles.

核心插件与构建生命周期密切相关。

Maven defines three build lifecycles:  default, site and clean. Each lifecycle is composed of multiple phases, which run in order up to the phase specified in the mvn command.

Maven定义了三个构建生命周期。 默认网站清洁。每个生命周期由多个阶段组成,按顺序运行,直至mvn命令中指定的阶段。

The most important lifecycle is default, responsible for all steps in the build process, from project validation to package deployment.

最重要的生命周期是default,负责构建过程的所有步骤,从项目验证到软件包部署。

The site lifecycle is in charge of building a site, showing Maven related information of the project, whereas the clean lifecycle takes care of removing files generated in the previous build.

site生命周期负责建立网站,显示项目的Maven相关信息,而clean生命周期则负责删除上一次构建中产生的文件。

Many phases in all three lifecycles are automatically bound to the goals of core plugins. The referenced articles will go over these goals and the built-in bindings in detail.

所有这三个生命周期中的许多阶段都自动与核心插件的目标绑定。引用的文章将详细介绍这些目标和内置的绑定。

All plugins are enclosed in a build element of the POM:

所有插件都包含在POM的build元素中。

<build>
    <plugins>
        <!-- plugins go here -->
    </plugins>
</build>

3. Plugins Bound to the Default Lifecycle 

3.绑定在默认生命周期的插件

The built-in bindings of the default lifecycle are dependent on the value of the POM’s packaging element. For the sake of brevity, we’ll go over bindings of the most common packaging types:  jar and war.

默认生命周期的内置绑定取决于POM的packaging元素的值。为了简洁起见,我们将介绍最常见的打包类型的绑定。 jarwar

Here’s a list of the goals that are bound to each phase of the default lifecycle in the format “phase -> plugin:goal”:

这里有一个与default生命周期的每个阶段绑定的目标列表,格式为”阶段->插件目标”

  • process-resources -> resources:resources
  • compile -> compiler:compile
  • process-test-resources -> resources:testResources
  • test-compile -> compiler:testCompile
  • test -> surefire:test
  • package -> ejb:ejb or ejb3:ejb3 or jar:jar or par:par or rar:rar or war:war
  • install -> install:install
  • deploy -> deploy:deploy

The goals above are contained in the following plugins. Follow the links for an article on each of the plugins:

上述目标包含在以下插件中。请按照链接查看关于每个插件的文章。

4. Other Plugins

4.其他插件

In addition to the plugins mentioned in the previous section, there are two other core plugins whose goals are bound to phases of the site and clean lifecycles:

除了上一节提到的插件外,还有两个核心插件,它们的目标与siteclean生命周期的各个阶段相绑定。

5. Conclusion

5.结论

In this article, we went over Maven build lifecycles and provided references to tutorials covering the core plugins of the Maven build tool in detail.

在这篇文章中,我们介绍了Maven的构建生命周期,并提供了详细介绍Maven构建工具的核心插件的教程参考。

The code examples of most of the referenced articles can be found over on GitHub.

大多数被引用的文章的代码实例可以在GitHub上找到over

« Previous

The Maven Site Plugin