How to associate maven antrun plugin with clean phase

I just translated the ant project into maven, however, since maven does not deal with deployment, I inject some antrun into the assembly. However, when I try to execute it, the plugin skips my tasks. for example, when I run mvn clean antrun: run, I get the following message: No ant target defined - SKIPPED. the same thing happens with the second phase in which I try to redefine the deployment phase in order to perform the actual deployment, rather than upload to the repository.

Below you will find an excerpt of my pom.xml (type: 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> 
+7
maven maven-antrun-plugin
source share
1 answer

In pom.xml you define two types of execution:

  • One is associated with the clean phase.
  • One is associated with the deploy phase. Please note that, by the way, for Maven << 22> does not mean deploying my (web application) to the server, but deploying the artifact to a remote repository. Read more about deploy plugin information .

So, if you run the mvn deploy command when the Maven life cycle reaches the deploy phase, it will start the plugin execution (the second one in your pom.xml ).

However, in your case, you are not executing the default Maven life cycle, since your mvn antrun: run command (I do not consider the clean target here, as this does not matter for the problem). This can be translated into Maven to run the antrun plugin with the launch of the target. The problem is that you are not defining any configuration (containing Ant tasks) to directly call your Ant plugin.

So, two solutions:

  • Bind the second run to the install phase, and then run mvn clean install instead of mvn antrun:run . Please note that in this case you will run the entire Maven life cycle (i.e. Compilation, tests, packaging).
  • Create the configuration of this plugin not related to any execution. In the XML view, just add (or move) the second <configuration> block as a child of the <plugin> definition.

If you choose the second solution, you will have pom.xml , like this one:

  <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> 
+11
source share

All Articles