Maven java maven-antrun-plugin

发布于 2025-01-04 05:29:54 字数 3549 浏览 1 评论 0原文

我遇到了以下问题:

我在 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] ------------------------------------------------------------------------

所以执行任务执行任务之间最终没有输出,而是插件本身被考虑在内。知道为什么吗?

I've got a following problem:

I have configured a ant plugin within my pom.xml file for a verify phase. The task is simply to echo some string to console. The problem is that I see my execution being taken into accoutn, but no tasks get executed. Have anybody encountered similar problem? Below is the code of my pom.xml file:

<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>

The output I get when running mvn verify is as follows:

[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] ------------------------------------------------------------------------

So there is eventually no output between Executing tasks and Executed tasks, but the plugin itself is taken to account. Any idea why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

殤城〤 2025-01-11 05:29:54

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

以下片段对我有用。请注意, ./hey 是 ant mkdir 任务。此外,task已弃用 支持目标

   <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>

Possibly the 1.1 version of the maven antrun plugin has bugs.

The following snippet works for me. Note that <mkdir>./hey</mkdir is incorrect syntax for ant mkdir task. Also, task is deprecated in favor of 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>
丶情人眼里出诗心の 2025-01-11 05:29:54

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

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

Try doing some other task during verify , like : "copying some file into some directory"

<copy file="${project.build.directory}/somefile" todir="some dir" 
 overwrite="true" />
心是晴朗的。 2025-01-11 05:29:54

正如一些评论中提到的,使用该插件的最新版本(1.7)。另外,将 标记替换为 标记。例如:

<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>

As mentioned in some of the comments use the latest version (1.7) of the plugin. Also, replace your <task> tags with <target> tags. For example:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文