繁体   English   中英

如何从Maven2运行一个蚂蚁目标?

[英]How to run an ant target from Maven2?

如何使用命令行中的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>

如何使用命令行中的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 )。

3.为特殊的default-cli执行Id提供执行级configuration

<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 ),直接从命令行调用的目标可以使用名为default-cli的特殊executionId在POM中与其他插件调用分开配置。 换句话说,上述配置仅在从命令行调用插件时使用。

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

参考

你可以,偷偷摸摸。

在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的testTarget将会运行。

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

<ant andfile="${buildFile}" target="${targetName}" inheritAll="true" inheritRefs="true"/>

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

<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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM