Maven插件maven-antrun-plugin的使用

如下引用官方的介紹http://maven.apache.org/plugins/maven-antrun-plugin/html

1、什麼是maven-antrun-plugin?apache

該插件提供從Maven內運行Ant任務的功能。您甚至能夠將您的Ant腳本嵌入POM!app

這個插件不是提供污染POM的手段意圖,所以它鼓勵全部Ant任務移動到build.xml文件並使用Ant的POM的<ant/> task調用它(或者說全部在build.xml文件的Ant任務移動到POM中,並使用<ant/> task調用它)。maven

這個插件的主要目的之一是方便從Ant基礎項目遷移到Maven。某些項目可能沒法遷移,由於它們依賴於默認狀況下Maven不提供的自定義構建功能。ui

2、座標spa

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>

3、簡單使用,參考官網http://maven.apache.org/plugins/maven-antrun-plugin/usage.html插件

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <phase> <!-- Maven的生命週期階段 --> </phase>
            <configuration>
              <target>

                <!--
                  將任務Ant任務放在這裏,還能夠在這裏添加一個build.xml文件
                -->

              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

固然,如上所示的配置其實還少了幾個屬性,不過這不影響運行,由於默認是繼承超級POM的。code

提示:xml

一、Maven的生命週期階段參考:http://www.cnblogs.com/EasonJim/p/6816340.htmlhtm

二、在<target>中的標籤只有搞過Ant集成的纔會比較熟悉,若是想要使用其中的標籤,參考官方提供的文檔:http://ant.apache.org/manual/tasksoverview.html

如下將展現官方實際項目上的POM:

http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html

http://maven.apache.org/plugins/maven-antrun-plugin/examples/tasksAttributes.html

http://maven.apache.org/plugins/maven-antrun-plugin/examples/customTasks.html

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-test-app</artifactId>
  <groupId>my-test-group</groupId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
              <target>
                <property name="compile_classpath" refid="maven.compile.classpath"/>
                <property name="runtime_classpath" refid="maven.runtime.classpath"/>
                <property name="test_classpath" refid="maven.test.classpath"/>
                <property name="plugin_classpath" refid="maven.plugin.classpath"/>

                <echo message="compile classpath: ${compile_classpath}"/>
                <echo message="runtime classpath: ${runtime_classpath}"/>
                <echo message="test classpath:    ${test_classpath}"/>
                <echo message="plugin classpath:  ${plugin_classpath}"/>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

注意:<id>爲惟一的標識,能夠是任意。

4、Ant插件只有一個目標(goal)

既:antrun:run,參考:http://maven.apache.org/plugins/maven-antrun-plugin/run-mojo.html

5、其它Ant集成例子

參考:http://maven.apache.org/plugins/maven-antrun-plugin/tasks/tasks.html

 

總結:

一、簡單的說這個Ant插件就是爲了方便把以前在Ant集成的任務遷移到Maven中去、

二、在Maven中的<target>中能夠很方便的使用Ant的標籤。

三、經過<phase>能夠很方便的指定Maven的生命週期。而且指定生命週期以後,能夠在生命週期運行時直接觸發<target>中的任務。

相關文章
相關標籤/搜索