【问题标题】:Maven Antrun Not Executing TasksMaven Antrun 不执行任务
【发布时间】:2011-09-10 10:40:51
【问题描述】:

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

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

当我执行 mvn antrun:run 时,我只收到以下消息。 未定义 ant 目标 - 已跳过

我做错了什么?

这是我的 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>

【问题讨论】:

    标签: maven maven-antrun-plugin


    【解决方案1】:

    试试这个

    <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”来执行其他操作可能会适得其反。

    【讨论】:

    • 几个小时后很多谷歌,这篇文章拯救了我的一天。谢谢。有人知道为什么使用 antrun:run@custom_id 不起作用? [ERROR] Could not find goal 'run@copy'
    • @ 功能在 Maven 3.3.1 中实现。您可能正在运行旧版本。见issues.apache.org/jira/browse/MNG-5768
    【解决方案2】:

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

    mvn compile

    这将是必要的。

    【讨论】:

    • 谢谢!这是对如何调用 pom 的误解。
    • 这里有一个重要注意事项(我花了大约 1 小时才弄清楚):如果您使用 mvn antrun:run@myexecutionid 并且您的 antrun-target 位于一个插件中,该插件位于在配置文件中,您绝对需要在命令行中包含配置文件的名称。例如:mvn -P myprofile antrun:run@myexecutionid.
    猜你喜欢
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多