maven插件_Maven插件

maven插件

Plugin in maven is the one of the vital feature that is basically used to reuse the common build logic across different projects. Plugins are the ones through which all the tasks like compiling code, testing them with the junits, creating jar/war/ear files and documentation of the projects are carried out. Most of the work in maven is done using plugins, since the dependencies (jar files) are added only to the classpath while executing tasks.

maven插件是一项重要功能,基本上可用于在不同项目之间重用通用构建逻辑。 插件是用来执行所有任务的工具,例如编译代码,使用junit测试它们,创建jar / war / ear文件和项目文档。 由于依赖项(jar文件)仅在执行任务时添加到类路径中,因此maven中的大多数工作都是使用插件完成的。

So, maven is nothing but a plugin execution framework in which every tasks are accomplished by the usage of plugins.

因此,maven就是一个插件执行框架,其中每个任务都通过使用插件来完成。

Below are the basic list of tasks that are handled by plugins in maven :

以下是由maven中的插件处理的基本任务列表:

  • Creating jar/war/ear files.

    创建jar / war / ear文件。

  • Code compilation

    代码编译

  • Unit testing of the code.

    代码的单元测试。

  • Project documentation

    项目文件

Behavior of any plugin can be changed using a set of parameters exposed by each plugin goal (also known as Mojo). A Mojo in maven is just a goal, basically specifies the metadata of a goal - goal name, which phase it fits into and parameters expected by the goal.

可以使用每个插件目标(也称为Mojo)公开的一组参数来更改任何插件的行为。 Maven中的Mojo只是一个目标,基本上指定了目标的元数据-目标名称,该阶段适合目标的阶段以及目标期望的参数。

Maven插件的类型 (Types of Maven Plugins)

Basically 2 important types of plugins exist in maven as listed below :

基本上,Maven中存在两种重要的插件类型,如下所示:

  1. Build Plugins - Basically these plugins will execute during the build phase. These plugins are defined under the <build> element in pom.xml

    构建插件 -基本上,这些插件将在构建阶段执行。 这些插件在pom.xml的<build>元素下定义

  2. Report Plugins - These plugins are executed during the site generation (report or javadocs generation) phase. These plugins will be configured under the <reporting> element in pom.xml

    报告插件 -这些插件在网站生成(报告或javadocs生成)阶段执行。 这些插件将在pom.xml中的<reporting>元素下配置。

一些常见的Maven插件 (Some Common Maven Plugins)

Below are list of commonly used plugins in any java projects built using maven :

以下是使用maven构建的任何Java项目中的常用插件列表:

Plugin nameDescription
cleanUsed to delete the target directory in order to clean up the earlier build artifacts
compilerTo compile java source files
surefileExecutes the Junit tests and generate the reports.
jarBuild the jar file of the project
warBuild the war file of the project
javadocGenerates the javadocs of the project
antrunRuns a set of ant tasks specified in any stage/phase of the build
插件名称 描述
清洁 用于删除目标目录以清理较早的构建工件
编译器 编译Java源文件
确定文件 执行Junit测试并生成报告。
生成项目的jar文件
战争 建立项目的战争档案
Java文档 生成项目的javadocs
安特伦 运行在构建的任何阶段/阶段中指定的一组ant任务

pom.xml中的示例插件 (Sample plugin in pom.xml)

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.orgname.orggroup</groupId>
  <artifactId>project</artifactId>
  <version>1.0</version>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <id>id.clean</id>
            <phase>clean</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <echo>Clean Phase</echo>
              </tasks>
            </configuration>
          </execution>     
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
  • Each plugin can have more than one goals to perform different set of tasks accordingly.

    每个插件可以有多个目标,以相应地执行不同的任务集。

  • Starting phase of any plugin can be defined.

    可以定义任何插件的开始阶段。

  • Tasks can be configured associated to each goal of the plugin defined.

    可以将任务配置为与定义的插件的每个目标相关联。

Maven插件的好处 (Benefits of Maven Plugins)

  • More detailed and well architecture.

    更详细和完善的架构。

  • A managed life cycle

    受控的生命周期

  • Implementation of multiple languages

    多种语言的实现

  • Reusability of the common build logic.

    通用构建逻辑的可重用性。

  • Ability to write maven plugins completely in java

    能够完全用Java编写Maven插件

翻译自: https://www.studytonight.com/maven/maven-plugins

maven插件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值