Domanda

I'm using the exec-maven-plugin to execute a batch file with maven. I had it running during the package phase, but I need it to run earlier. The compilation phase would be fine.

The batch script generates a properties file that contains the svn version. When the phase is set to package, it looks like is does this after it makes the war file. Too late for me.

However, in eclipse I get this error:

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

The relevant section of my 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>

First, is exec-maven-plugin still the right tool?

Second, can it be run during an earlier phase than package? Is this documented anywhere? The mailing list archive links on the exec-maven-plugin project page are out of date.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top