I have a strange behaviour with my Maven build, using the exec-maven-plugin. I note that, even if associated with the process-classes phase, the exec-maven-plugin (using the java goal) regoes through the validate phase.
I can't find any explanation for that, it seems to me it goes against the default build lifecyle.
Here is a part of my pom:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<!-- Display Maven 3 phases for strange VALIDATE phase behaviour (executed twice through the exec-maven-plugin) -->
<execution>
<id>id.validate</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>in validate phase (1 of 23)</echo>
</target>
</configuration>
</execution>
<execution>
<id>id.initialize</id>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>in initialize phase (2 of 23)</echo>
</target>
</configuration>
</execution>
[...]
</executions>
</plugin>
<!-- Generating Scripts -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>generateScripts</id>
<phase>process-classes</phase>
<goals>
<!-- java goal executes the supplied java class in the current VM with the enclosing project's dependencies as classpath. -->
<goal>java</goal>
</goals>
<configuration>
<classpathScope>compile</classpathScope>
<!-- we include all the dependencies declared for the project in the classpath for exec-maven-plugin target class (GenerateScripts) -->
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<mainClass>com.tsc.GenerateScripts</mainClass>
<!-- arguments from before maven 3 migration -->
<arguments>
[...]
</arguments>
</configuration>
</execution>
</executions>
</plugin>
[...]
</plugins>
And here are the logs after a mvn package
:
[INFO]
[INFO] --- maven-antrun-plugin:1.7:run (id.validate) @ scriptsGeneration ---
[INFO] Executing tasks
main:
[echo] in validate phase (1 of 23)
[INFO] Executed tasks
[INFO]
[INFO] --- maven-antrun-plugin:1.7:run (id.initialize) @ scriptsGeneration ---
[INFO] Executing tasks
main:
[echo] in initialize phase (2 of 23)
[INFO] Executed tasks
[INFO]
[INFO] --- maven-antrun-plugin:1.7:run (id.generate-sources) @ scriptsGeneration ---
[INFO] Executing tasks
[...]
[INFO] --- maven-antrun-plugin:1.7:run (id.compile) @ scriptsGeneration ---
[INFO] Executing tasks
main:
[echo] in compile phase (7 of 23)
[INFO] Executed tasks
[INFO]
[INFO] --- maven-antrun-plugin:1.7:run (id.process-classes) @ scriptsGeneration ---
[INFO] Executing tasks
main:
[echo] in process-classes phase (8 of 23)
[INFO] Executed tasks
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (generateScripts) @ scriptsGeneration >>>
[INFO]
[INFO] --- maven-antrun-plugin:1.7:run (id.validate) @ scriptsGeneration ---
[INFO] Executing tasks
main:
[echo] in validate phase (1 of 23)
[INFO] Executed tasks
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (generateScripts) @ scriptsGeneration <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (generateScripts) @ scriptsGeneration ---
[...]
As can be seen the [echo] in validate phase (1 of 23)
appears twice:
If someone has an explanation, it would be greatly appreciated.
exec:java
runs a forked lifecycle up to the validate phase, i.e. when you start build your project, during the run of exec:java
, a secondary run of your build is started.
Thus your validate phase is called twice.
see: http://www.mojohaus.org/exec-maven-plugin/index.html:
- Invokes the execution of the lifecycle phase validate prior to executing itself.