Maven Antrun不执行任务

时间:2011-06-07 21:37:37

标签: maven maven-antrun-plugin

我正在使用Maven AntRun插件1.6并且从他们的示例中我无法编写以下要执行的ant任务。

示例网址:http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html

当我执行mvn antrun:run时,我只收到以下消息。 没有定义蚂蚁目标 - SKIPPED

我做错了什么?

这是我的POM:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</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>

2 个答案:

答案 0 :(得分:23)

试试这个

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>default-cli</id>
                    <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>

注意ID

<id>default-cli</id>

并运行命令

mvn antrun:run

这样做的原因: 如果你实际上不想“编译”,运行“mvn compile”来执行其他操作可能会适得其反。

答案 1 :(得分:7)

由于您已在pom.xml中配置了maven antrun插件,因此您只需调用为插件配置的生命周期目标。在这种情况下

mvn compile

这将是必要的。