zoukankan      html  css  js  c++  java
  • maven插件

    一。生命周期

    There are three built-in build lifecycles: default, clean and site.

    The default lifecycle handles your project deployment

    the clean lifecycle handles project cleaning

    the site lifecycle handles the creation of your project's site documentation.

    1.A Build Lifecycle is Made Up of Phases

    Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.

    2.A Build Phase is Made Up of Plugin Goals

    However, even though a build phase is responsible for a specific step in the build lifecycle, the manner in which it carries out those

    responsibilities may vary. And this is done by declaring the plugin goals bound to those build phases.

    A plugin goal represents a specific task (finer than a build phase) which contributes to the building and managing of a project. It

    may be bound to zero or more build phases. A goal not bound to any build phase could be executed outside of the build lifecycle

    by direct invocation. 

    链接:introduction-to-the-lifecycle.html

    二。插件开发

    What is a Mojo?

    A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one

    or more related mojos. In short, a mojo is a maven goal, to extend functionality not already found in maven.

    链接:mojo-api-specification.html

    三。示例

    1. mvn package

    Maven为了在最大程度上简化我们的工作,因而定义了lifecycle, phase and goal。我们仅仅需要简单的运行:

    mvn package(package是一个phase), 包就自动打好了。

    而实际上,mvn package这个命令会运行以下6个步骤(左边这列是步骤名,同时也是phase的名字,右边是对应的goal):

    process-resources              resources:resources
    compile                             compiler:compile
    process-test-resources      resources:testResources
    test-compile                      compiler:testCompile
    test                                   surefire:test
    package                            jar:jar

    phase其实就是goal的容器。实际被执行的都是goal。phase被执行时,实际执行的都是被绑定到该phase的goal。

    goal与goal之间是独立的。因此单独执行一个goal不会导致其他goal被执行。

    mvn clean dependency:copy-dependencies package

    clean是phase。

    dependency:copy-dependencies是plugin-in dependency 的goal copy-dependencies。

    package也是一个phase。

    maven会顺序执行这3个对象中包含的所有goal。

    2. 编译时检查代码

           <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>nameCheckProcessor</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>compile</phase>
                        <configuration>
                            <processors>
                                <processor>auto.NameCheckProcessor</processor>
                            </processors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

    3.How can I create an executable JAR with dependencies using Maven?

    <build>
      <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <mainClass>fully.qualified.MainClass</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
        </plugin>
      </plugins>
    </build>

    4.

    当我们开发人员进入项目组进行开发前,要准备开发环境,而领导总是会强调工具的统一,编译环境的统一。比如要求所有开发人员使用JDK1.8进行开发。

    开发人员接下来就是去下载指定版本的JDK,然后开始开发。但是如果开发人员的机器配置比较多,有好几个版本的JDK,而他虽然下载了JDK1.8,但是

    忘记配置环境变量,很有可能他用了JDK1.6进行的编译。Maven Enforcer plugin就是来解决这类问题。Enforcer可以在项目validate时,对项目环境进行检查。

    5.

    apereo-cas-overlay

     overlay可以把多个项目war合并成为一个项目,并且如果项目存在同名文件,那么主项目中的文件将覆盖掉其他项目的同名文件。

  • 相关阅读:
    杭电 HDU 1279 验证角谷猜想
    C# SQL 整表插入
    iframe截取站点的部分内容
    Thrift安装介绍
    赵雅智_Swift(3)_swift凝视
    Android API 文档 离线秒开方法
    xml文件的根节点layout_width或者layout_height设置无效果的原因分析
    函数指针使用演示样例(參考Linux-内核代码)
    eclipse中的项目受svn管理
    野人与传教士问题
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/4882441.html
Copyright © 2011-2022 走看看