Maven插件maven-antrun-plugin的使⽤
以下引⽤官⽅的介绍:
⼀、什么是maven-antrun-plugin?
该插件提供从Maven内运⾏Ant任务的功能。您甚⾄可以将您的Ant脚本嵌⼊POM!
这个插件不是提供污染POM的⼿段意图,因此它⿎励所有Ant任务移动到l⽂件并使⽤Ant的POM的调⽤它(或者说所有在l⽂件的Ant任务移动到POM中,并使⽤<ant/> task调⽤它)。
这个插件的主要⽬的之⼀是⽅便从Ant基础项⽬迁移到Maven。某些项⽬可能⽆法迁移,因为它们依赖于默认情况下Maven不提供的⾃定义构建功能。
⼆、坐标
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
三、简单使⽤,参考官⽹
<project>
[...]
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase><!-- Maven的⽣命周期阶段 --></phase>
<configuration>
<target>
<!--
将任务Ant任务放在这⾥,还可以在这⾥添加⼀个l⽂件
-->
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
当然,如上所⽰的配置其实还少了⼏个属性,不过这不影响运⾏,因为默认是继承超级POM的。
ant design 提⽰:
1、Maven的⽣命周期阶段参考:
2、在<target>中的标签只有搞过Ant集成的才会⽐较熟悉,如果想要使⽤其中的标签,参考官⽅提供的⽂档:
以下将展⽰官⽅实际项⽬上的POM:
<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="mavenpile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="st.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>为唯⼀的标识,可以是任意。
四、Ant插件只有⼀个⽬标(goal)
既:antrun:run,参考:
五、其它Ant集成例⼦
参考:
总结:
1、简单的说这个Ant插件就是为了⽅便把之前在Ant集成的任务迁移到Maven中去、
2、在Maven中的<target>中可以很⽅便的使⽤Ant的标签。
3、通过<phase>可以很⽅便的指定Maven的⽣命周期。并且指定⽣命周期之后,可以在⽣命周期运⾏时直接触发<target>中的任务。