使用与进程类阶段关联的exec-maven-plugin验证阶段使用两次

时间:2014-03-18 16:35:18

标签: maven exec-maven-plugin

我的Maven构建有一个奇怪的行为,使用 exec-maven-plugin 。 我注意到,即使与 process-classes 阶段相关联, exec-maven-plugin (使用 java 目标)通过验证阶段重新开始

我无法找到任何解释,在我看来它违背了默认的构建生命周期。

这是我的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>

以下是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 ---

[...]

可以看出,[echo] in validate phase (1 of 23)出现了两次:

  • &#34; normal&#34; 验证阶段
  • exec-maven-plugin 部分中的另一个与进程类阶段相关联的

如果有人有解释,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

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

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

请参阅:http://www.mojohaus.org/exec-maven-plugin/index.html

  
      
  • 在执行之前调用生命周期阶段的执行。
  •