Michal Pasinski
Michal Pasinski

Reputation: 578

maven java maven-antrun-plugin

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?

Upvotes: 1

Views: 2825

Answers (3)

Raghuram
Raghuram

Reputation: 52665

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>

Upvotes: 2

BenjaminLinus
BenjaminLinus

Reputation: 2120

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>

Upvotes: 0

Ramandeep Singh
Ramandeep Singh

Reputation: 5253

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

Upvotes: 0

Related Questions