2014-02-07 49 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化項目的最終配置。