1

我正在使用 exec-maven-plugin 使用 maven 执行批处理文件。我让它在打包阶段运行,但我需要它更早运行。编译阶段会很好。

批处理脚本生成一个包含 svn 版本的属性文件。当阶段设置为打包时,它看起来像是在制作war文件后执行此操作。对我来说太晚了。

但是,在eclipse中我得到这个错误:

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (execution: Version, phase: compile)

我的 pom.xml 的相关部分:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.2.1</version>
  <executions>
     <execution>
        <id>Version</id>
        <phase>compile</phase>
        <goals>
           <goal>exec</goal>
        </goals>
     </execution>
  </executions>
  <configuration>
     <executable>\my\path\version\version.bat</executable>
  </configuration>
</plugin>

首先,exec-maven-plugin 仍然是正确的工具吗?

其次,它可以在比包更早的阶段运行吗?这在任何地方都有记录吗?exec-maven-plugin 项目页面上的邮件列表存档链接已过期。

4

1 回答 1

1

The problem is not with exec-maven-plugin but with m2e plugin which doesn't know what to do with exec-maven-plugin. The simplest way to fix the problem is to ignore that plugin during build within Eclipse (right click on the problem and use a proposed solution). Command-line invocation will still run the batch.

If you wish m2e can be configured more sophisticately. Take a look on the snippet from one of my projects:

<pluginManagement>
  <plugins>
    ...
    <!-- The following plugin is solely to make Eclipse happy, it's not executed during regular build -->
    <plugin>
      <groupId>org.eclipse.m2e</groupId>
      <artifactId>lifecycle-mapping</artifactId>
      <version>1.0.0</version>
      <configuration>
        <lifecycleMappingMetadata>
          <pluginExecutions>
            <pluginExecution>
              <pluginExecutionFilter>
                <groupId>com.googlecode.cmake-maven-project</groupId>
                <artifactId>cmake-maven-plugin</artifactId>
                <versionRange>[2.8.11-b4-SNAPSHOT,)</versionRange>
                <goals>
                  <goal>generate</goal>
                  <goal>compile</goal>
                </goals>
              </pluginExecutionFilter>
              <action>
                <execute />
              </action>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

Also you may run virtually any goal of any plugin during any phase or completely disable its execution. Here I disable default-deploy of the maven-deploy-plugin and assign a customized goal deploy-file to the deploy phase:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-deploy-plugin</artifactId>
      <version>2.5</version>
      <executions>
        <execution>
          <id>default-deploy</id>
          <phase>none</phase>
        </execution>
        <execution>
          <id>versioned-deploy</id>
          <goals>
            <goal>deploy-file</goal>
          </goals>
          <phase>deploy</phase>
          <configuration>
            <file>${project.build.directory}/${project.build.finalName}.${project.packaging}</file>
            <repositoryId>${project.distributionManagement.repository.id}</repositoryId>
            <url>${project.distributionManagement.repository.url}</url>
            <generatePom>false</generatePom>
            <pomFile>${effective_dir}/pom.xml</pomFile>
          </configuration>
        </execution>
      </executions>
    </plugin>

There's a special mvn help:effective-pom command which allows you to understand what is the final configuration of a mavenized project.

于 2014-02-07T03:37:20.097 回答