1
votes

i am new to maven and learning how and when phases/goals get executed in plugin

Say i have below code snippet in my pom

 <plugin>
   <groupId>org.codehaus.modello</groupId>
   <artifactId>modello-maven-plugin</artifactId>
   <version>1.4</version>
 </plugin>

Now if i execute mvn install, all phases(and all goals corresponding to each phase) of modello that comes prior to install will be executed. Right?

But if do below modification to introduce specific goal, only one goal i.e java goal will be executed (as it under generate-sources phase which comes prior to install phase). Is that correct?

 <plugin>
   <groupId>org.codehaus.modello</groupId>
   <artifactId>modello-maven-plugin</artifactId>
   <version>1.4</version>
   <executions>
     <execution>
       <goals>
         <goal>java</goal>
       </goals>
     </execution>
   </executions>
 </plugin>
1

1 Answers

1
votes

No, it doesn't work like that. First of all, please use mvn verify (instead of install), unless you really want your project to be copied to your local repository.

If you only specify a plugin, which is not part of the default lifecycle (e.g. maven-compiler-plugin is already specified for the default lifecycle, all jars need to compile, right?), nothing will happen. So you need to specify which goals need to be executed within an execution-block. In some cases the goal has a default phase to bind to, e.g. modello:java binds by default to the generate-sources-phase. In this case you don't have to specify a <phase> in the execution-block.