开发者

Maven exec plugin execution conundrum

开发者 https://www.devze.com 2023-02-10 23:51 出处:网络
Sample maven build file: <project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"

Sample maven build file:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>1.0.0</version>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>my-validation-one</id>
                <phase>validate</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <executable>echo</executable>
              <arguments>
                <argument>"My validation one"</argument>
              </arguments>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>my-validation-two</id>
                <phase>validate</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
开发者_StackOverflow中文版              </execution>
            </executions>
            <configuration>
              <executable>echo</executable>
              <arguments>
                <argument>"My validation two"</argument>
              </arguments>
            </configuration>
          </plugin>
        </plugins>
      </build>
  <dependencies>
  </dependencies>
</project>

Sample maven output:

$ mvn install
/cygdrive/c/Program Files/Java/jdk1.5.0_20/bin/java -classpath C:\Program Files\Apache Software Foundation\apache-maven-2.2.1/boot/classworlds-1.1.jar -Dclassworlds.conf=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1/bin/m2.conf -Dmaven.home=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1 org.codehaus.classworlds.Launcher "install"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - test:test:jar:1.0.0
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [exec:exec {execution: my-validation-one}]
[INFO] "My validation two"
[INFO] [exec:exec {execution: my-validation-two}]
[INFO] "My validation two"
[INFO] [resources:resources {execution: default-resources}]
<snip>

Shouldn't my-validation-one echo "My validation one" to the console? Why does it seem like maven is getting its wires crossed?

Thanks, Steven


You should put the configuration specific to the execution within the execution block. Then it should work correctly.

 <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>my-validation-two</id>
        <phase>validate</phase>
        <goals>
          <goal>exec</goal>
        </goals>
        <configuration>
           <executable>echo</executable>
           <arguments>
              <argument>"My validation two"</argument>
           </arguments>
        </configuration>
      </execution>
    </executions>
  </plugin>

Also, if both the executions are bound to same phase and goal, you can combine then within executions block instead of declaring the plugin twice.

0

精彩评论

暂无评论...
验证码 换一张
取 消