4

如何从命令行使用 antrun-plugin 运行特定目标?

mvn antrun:run不会让它运行。


<project>
    ...
    <build>
        <plugins>
            ...
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>myExecution</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <ant target="myTarget" inheritRefs="true">
                                    ...
                                </ant>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>

                <dependencies>
                    ...
                </dependencies>
            </plugin>
            ...
        </plugins>
        ...
    </build>
    ...
</project>
4

4 回答 4

8

如何从命令行使用 antrun-plugin 运行特定目标?

要严格回答这个问题,你不能,你也不能。

你可以做的是:

1.提供插件级别configuration

<plugin>
   <artifactId>maven-antrun-plugin</artifactId>
   <configuration>
       ....
   </configuration>
</plugin>

并且在调用插件时将使用此配置(无论插件如何调用:从 cli,生命周期的一部分)。

2.提供一个执行级别configuration(这就是你所做的)

<plugin>
   <artifactId>maven-antrun-plugin</artifactId>
   <executions>
       <execution>
           <id>myExecution</id>
           <phase>deploy</phase>
           <goals>
               <goal>run</goal>
           </goals>
           <configuration>
               <tasks>
                   <ant target="myTarget" inheritRefs="true">
                       ...
                   </ant>
               </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

然后调用插件绑定的阶段(deploy在本例中)。

configuration3.为特殊的default-cli执行ID提供一个执行级别

<plugin>
   <artifactId>maven-antrun-plugin</artifactId>
   <executions>
       <execution>
           <id>default-cli</id>
           <configuration>
               <tasks>
                   <ant target="myTarget" inheritRefs="true">
                       ...
                   </ant>
               </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

从 Maven 2.2.0 开始(参见MNG-3401),直接从命令行调用的目标可以在 POM 中与其他插件调用分开配置,使用名为 的特殊 executionId default-cli。换句话说,上面的配置只会在从命令行调用插件时使用。

但无论如何,您不能在元素target内调用特定的 Ant。configuration你可能会弄乱配置文件来实现一些接近的东西,但是,如果你真的想朝这个方向发展,我的建议是使用 Ant。

参考

于 2010-10-19T20:55:20.060 回答
2

你可以,偷偷摸摸。

在 pom.xml 中:

...
<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <configuration>
        <target>
            <ant target="trampoline" />
        </target>
    </configuration>
</plugin>
...

在 build.xml 中:

...
<target name="trampoline">
    <echo message="Executing target '${mvnAntTarget}'"/>
    <antcall target="${mvnAntTarget}" />
</target>

<target name="testTarget">
    <echo message="Yay, I'm a test target.."/>
</target>
....

然后,通过运行:

$ mvn antrun:run -DmvnAntTarget=testTarget

Ant'stestTarget将运行。

于 2014-02-20T16:19:23.130 回答
1

请参阅以下示例:http ://docs.codehaus.org/display/MAVENUSER/Antrun+Plugin 基本上在常规 build.xml 中编写您的 ant 目标。然后定义一个单独<target>的配置,您可以在其中动态决定什么是 buildFile 名称和 targetName 并执行

<ant andfile="${buildFile}" target="${targetName}" inheritAll="true" inheritRefs="true"/>
于 2013-07-19T21:36:12.773 回答
0

我不太确定这是它不起作用的原因,但您使用的语法已被弃用。你应该有类似的东西:

<configuration>
  <target name="myTarget">
    <!--
      Place any Ant task here. You can add anything
      you can add between <target> and </target> in a
      build.xml.
    -->    
  </target>
<configuration>

更多细节在这里: http ://maven.apache.org/plugins/maven-antrun-plugin/usage.html

于 2010-10-19T17:31:19.960 回答