【问题标题】:maven java maven-antrun-pluginmaven java maven-antrun-plugin
【发布时间】:2012-02-10 14:41:22
【问题描述】:

我遇到了以下问题:

我在我的 pom.xml 文件中为验证阶段配置了一个 ant 插件。任务只是将一些字符串回显到控制台。问题是我看到我的执行被计入账户,但没有执行任何任务。有没有人遇到过类似的问题?下面是我的 pom.xml 文件的代码:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mp</groupId>
<artifactId>parentApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parentApp</name>
<description>This is just to test pom inheritance</description>


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <defaultGoal>package</defaultGoal>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <id>echodir</id>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <phase>verify</phase>
                    <inherited>true</inherited>
                    <configuration>
                        <task>
                            <echo>*************************************************** Build Dir</echo>
                            <mkdir>./hey</mkdir>
                        </task>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-core</artifactId>
            <version>5.1.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
    </dependencies>
</dependencyManagement>

我在运行mvn verify时得到的输出如下:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parentApp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-antrun-plugin:1.1:run (echodir) @ parentApp ---
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.321s
[INFO] Finished at: Thu Feb 09 17:28:01 CET 2012
[INFO] Final Memory: 2M/121M
[INFO] ------------------------------------------------------------------------

所以Executing tasksExecuted tasks之间最终没有输出,但是插件本身是考虑在内的。知道为什么吗?

【问题讨论】:

  • maven-antrun-plugin1.6 ??
  • 您是否尝试过使用 -e 或 -X 标志运行 maven 以查看预期输出是否在调试输出中?即mvn -e verifymvn -X verify
  • 尝试删除mkdir 命令,看看您是否只有echo 是否有效。另外,我会尝试使用该插件的更新版本(当前为 1.7)

标签: java maven ant


【解决方案1】:

可能1.1版本的maven antrun插件有bug。

以下 sn-p 对我有用。请注意,&lt;mkdir&gt;./hey&lt;/mkdirant mkdir task 的不正确语法。另外,taskdeprecated 支持 target

   <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
            <execution>
                <id>echodir</id>
                <goals>
                    <goal>run</goal>
                </goals>
                <phase>verify</phase>
                <inherited>true</inherited>
                <configuration>
                    <target>
                        <echo>*************************************************** Build Dir</echo>
                        <mkdir dir="hey"/>
                    </target>
                </configuration>
            </execution>
        </executions>
    </plugin>

【讨论】:

    【解决方案2】:

    在验证期间尝试做一些其他任务,例如:“将一些文件复制到某个目录”

    <copy file="${project.build.directory}/somefile" todir="some dir" 
     overwrite="true" />
    

    【讨论】:

      【解决方案3】:

      正如在某些 cmets 中提到的,使用插件的最新版本 (1.7)。另外,用&lt;target&gt; 标签替换你的&lt;task&gt; 标签。例如:

      <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.7</version>
          <executions>
              <execution>
                  <id>echodir</id>
                  <goals>
                      <goal>run</goal>
                  </goals>
                  <phase>verify</phase>
                  <inherited>true</inherited>
                  <configuration>
                      <target>
                          <echo>*************************************************** Build Dir</echo>
                      </target>
                  </configuration>
              </execution>
          </executions>
      </plugin>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-19
        • 1970-01-01
        • 1970-01-01
        • 2012-05-30
        • 2013-09-18
        • 1970-01-01
        • 2010-11-26
        相关资源
        最近更新 更多