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

Arm*_*and 4 ant maven-2 maven-antrun-plugin

如何使用命令行中的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>
Run Code Online (Sandbox Code Playgroud)

Pas*_*ent 7

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

要严格回答这个问题,你不能,而你却不能.

你能做的是:

1.提供插件级别 configuration

<plugin>
   <artifactId>maven-antrun-plugin</artifactId>
   <configuration>
       ....
   </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

调用插件时将使用此配置(无论调用插件的方式如何:来自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>
Run Code Online (Sandbox Code Playgroud)

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

3.为configuration特殊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>
Run Code Online (Sandbox Code Playgroud)

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

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

参考