为什么Maven跳过我的自定义生成源执行?

时间:2013-09-10 14:30:37

标签: maven compilation

我使用.thrift -> .java添加了maven-antrun-plugin的执行,作为生成源阶段的一部分。但是当我输入mvn generate-sources时,Maven会跳过此执行。

知道为什么会这样做吗?

的pom.xml:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

...

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <tasks>
                <exec executable="${thrift.executable}">
                  <arg value="--gen" />
                  <arg value="java:beans" />
                  <arg value="-o" />
                  <arg value="src/main/java/com/... " />
                  <arg value="src/main/thrift/... .thrift" />
                </exec>
              </tasks>
            </configuration>
          </execution>
          <execution>
            <id>clean</id>
            <phase>clean</phase>
            <configuration>
              <tasks>
                <delete>
                  <fileset dir="src/main/java/com/... " includes="... .java" />
                </delete>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

1 个答案:

答案 0 :(得分:1)

啊,我错过了目标。正确的片段是:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

...

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <tasks>
                <exec executable="${thrift.executable}">
                  <arg value="--gen" />
                  <arg value="java:beans" />
                  <arg value="-o" />
                  <arg value="src/main/java/com/... " />
                  <arg value="src/main/thrift/... .thrift" />
                </exec>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
          <execution>
            <id>clean</id>
            <phase>clean</phase>
            <configuration>
              <tasks>
                <delete>
                  <fileset dir="src/main/java/com/... " includes="... .java" />
                </delete>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>