Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the order of maven plugin execution

Tags:

maven-3

I am new to maven, I would like to change the order of the maven plugins execution.

In my pom.xml, I have maven-assembly-plugin and maven-ant-plugin.

  • maven-assembly-plugin for creating a zip file.
  • maven-ant-plugin for copying the zip file from target to some other directory.

When I run pom.xml, maven-ant-plugin got triggered, and looking for zip file finally I got the error saying zip file not found.

Please suggest to me the way how to run maven-assembly-plugin first before maven-ant-plugin so that it will find and copy the zip file to the corresponding directory.

like image 581
user1062115 Avatar asked Nov 23 '11 14:11

user1062115


People also ask

Do Maven plugins run in order?

Plugins in the same phase are executed in the declared order. Then the execution is : maven.

What is the correct syntax for executing a Maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”. For example mvn example:version .

What is the difference between plugin and pluginManagement tags?

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.


Video Answer


1 Answers

Since you say you are very new to Maven....Maven builds are executions of an ordered series of phases. These phases are determined by the lifecycle that is appropriate to your project based on its packaging.

Therefore, you control when a plugin's goal is executed by binding it to a particular phase.

Hope that helps.

EDIT: Also, since Maven 3.0.3, for two plugins bound to the same phase, the order of execution is the same as the order in which you define them. For example:

<plugin>   <artifactId>maven-plugin-1</artifactId>   <version>1.0</version>   <executions>     <execution>       <phase>process-resources</phase>       ...     </execution>   </executions> </plugin>  <plugin>   <artifactId>maven-plugin-2</artifactId>   <version>1.0</version>   <executions>     <execution>       <phase>process-resources</phase>       ...     </execution>   </executions> </plugin>  <plugin>   <artifactId>maven-plugin-3</artifactId>   <version>1.0</version>   <executions>     <execution>       <phase>generate-resources</phase>       ...     </execution>   </executions> </plugin> 

In the above instance, the execution order would be:

  1. maven-plugin-3 (generate-resources)
  2. maven-plugin-1 (process-resources)
  3. maven-plugin-2 (process-resources)
like image 75
Sri Sankaran Avatar answered Sep 17 '22 15:09

Sri Sankaran