1

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:

  • one in the "normal" validate phase
  • and an other one in the exec-maven-plugin section, associated with the process-classes phase

If someone has an explanation, it would be greatly appreciated.

4

1 回答 1

0

exec:java运行一个分叉的生命周期直到验证阶段,即当您开始构建项目时,在运行期间exec:java,您的构建的第二次运行开始。

因此,您的验证阶段被调用了两次。

见:http ://www.mojohaus.org/exec-maven-plugin/index.html :

  • 在执行自身之前调用生命周期阶段验证的执行。
于 2014-03-18T17:28:32.837 回答