2014-02-07 45 views
1

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

批处理脚本生成一个包含svn版本的属性文件。当阶段被设置为封装时,它看起来是之后它是否生成战争文件。对我来说太迟了。

然而,在日食我得到这个错误:

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的插件仍然是正确的工具吗?

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

+0

为什么你需要这样的批处理文件,因为这将使你的构建不再便携。除此之外,批处理文件正在做什么? – khmarbaise

回答

1

问题不在于exec-maven-plugin,而在于m2e插件,它不知道如何处理exec-maven-plugin。解决该问题的最简单方法是在Eclipse内构建期间忽略该插件(右键单击该问题并使用建议的解决方案)。命令行调用仍将运行该批处理。

如果您愿意m2e可配置更复杂。就拿上即可看从我的项目之一:

<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> 

你也可以在任何阶段运行任何插件的几乎任何目标或完全禁止其执行。在这里,我禁用maven-deploy-plugindefault-deploy和定制目标deploy-file分配给deploy阶段:

<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> 

有一个特殊的mvn help:effective-pom命令,它可以让你了解什么是Maven化项目的最终配置。