【问题标题】:How to bind maven antrun plugin to the clean phase如何将 maven antrun 插件绑定到 clean 阶段
【发布时间】:2011-04-28 00:48:08
【问题描述】:

我刚刚将一个 ant 项目翻译成 maven,但是由于 maven 并不真正处理部署,我在构建中引入了一些 antrun。但是,当我尝试执行它时,插件会跳过我的任务。例如,当我运行 mvn clean antrun:run 时,我收到以下消息:未定义 ant 目标 - 已跳过。在我试图覆盖部署阶段以进行实际部署而不是上传到存储库的第二阶段也是如此。

请在下面找到我的 pom.xml(类型:pom)的摘录:

            <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <id>clean</id>
                    <configuration>
                        <task>
                            <echo>Cleaning deployed website</echo>
                        </task>
                        <tasks>
                            <delete dir="${deployRoot}/mydir/${env}"/>
                        </tasks>
                    </configuration>
                    <phase>clean</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
                <execution>
                    <id>deployment</id>
                    <configuration>
                        <task>
                            <echo>Deploying website</echo>
                        </task>
                        <tasks>
                            <echo>Copying website artifact to deployment </echo>
                            <mkdir dir="${deployRoot}/mydir/${env}" />
                            <unzip
                                src="${project.basedir}/target/${env}.${project.version}.zip"
                                dest="${deployRoot}/mydir/${env}" />
                            <chmod perm="ugo+rx">
                                <fileset dir="${deployRoot}/mydir/${env}/web-exploded/bin">
                                    <include name="**/*.sh" />
                                    <include name="**/*.bat" />
                                </fileset>
                            </chmod>
                        </tasks>
                    </configuration>
                    <phase>deploy</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

【问题讨论】:

    标签: maven maven-antrun-plugin


    【解决方案1】:

    在您的pom.xml 中,您定义了两种类型的执行:

    • 一个链接到clean阶段
    • 一个链接到deploy 阶段。顺便提一下,对于 Maven,deploy 确实不是意味着在服务器上部署我的(网络)应用程序,而是在远程部署工件存储库。请阅读deploy plugin information 了解更多详情。

    因此,如果您运行命令 mvn deploy,当 Maven 生命周期到达 deploy 阶段时,它将运行插件执行(pom.xml 中的第二个)。

    但是,在您的情况下,您没有运行默认的 Maven 生命周期,因为您的命令是 mvn antrun:run(我不考虑 clean 目标在这里,因为这对问题无关紧要)。这可以在 Maven 中翻译为运行 antrun 插件,目标是运行。这样做的问题是您没有为对 Ant 插件的 直接 调用定义任何配置(其中包含 Ant 任务)。

    所以有两种解决方案:

    • 将第二次执行绑定到install 阶段,然后运行mvn clean install 而不是mvn antrun:run。请注意,在这种情况下,您将运行整个 Maven 生命周期(即编译、测试、打包)。
    • 为此插件创建一个不与任何执行相关的配置。从 XML 的角度来看,只需将第二个 &lt;configuration&gt; 块添加(或移动)为 &lt;plugin&gt; 定义的子块。

    如果您选择第二种解决方案,您将有一个像这样的pom.xml:

           <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <!-- For cleaning -->
            <executions>
                <execution>
                    <id>clean</id>
                    <configuration>
                        <task>
                            <echo>Cleaning deployed website</echo>
                        </task>
                        <tasks>
                            <delete dir="${deployRoot}/mydir/${env}"/>
                        </tasks>
                    </configuration>
                    <phase>clean</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <tasks>
                    <echo>Copying website artifact to deployment </echo>
                    ...
                </tasks>
            </configuration>
        </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-26
      • 2011-12-09
      • 2011-04-16
      • 1970-01-01
      相关资源
      最近更新 更多