1

I want to write addtional texts to the Java resource files (combine two .java files to one). And I write a python script to do so.

I also want to automate the steps (combines files, compile, package) using Maven. I am a newbie to Maven, I found that exec-maven-plugin could run the python script.

I tried to set<phase>process-resources</phase> to try to make it start before compile, but Eclipse complained that Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (execution: default, phase: process-resources)

below is my pom of the exec-maven-plugin:

  <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
            <execution>
                <phase>process-resources</phase> <!-- Eclipse complains an error here -->
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <executable>python</executable>
            <workingDirectory>src/main/python</workingDirectory>
            <arguments>
                <argument>combine.py</argument>
            </arguments> 
        </configuration>
    </plugin>

Anyone know that how could I implement this purpose? Thanks a lot.

Xiao
  • 12,235
  • 2
  • 29
  • 36

2 Answers2

3

This is the Eclipse M2e plugin trick. Sachin Shekhar R is right, but the answer is not clear enough for newbies like me. Here comes my understanding:

See http://wiki.eclipse.org/M2E_plugin_execution_not_covered.
There are two methods to do so in Eclipse M2e.

  1. use the code listed in Sachin Shekhar R's answer. Notice that this piece of code must under <pluginManagement><plugins> and <pluginManagement> must be inside <plugins>. sample code:

    <build>
    <plugins>
                <plugin>
                   <!-- plugins here-->
                </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>exec-maven-plugin</artifactId>
                                    <versionRange>[1.2.1,)</versionRange>
                                    <goals>
                                        <goal>exec</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore/>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    </build>
    

    This only works in the project.

  2. use the "Quick Fix" feature of the Eclipse M2e plugin. It exists after version 1.0. Find the error in Problems tab. Right click on it, select "Quick Fix". There would be a Quick Fix window popping up, select the second option Mark goal exec as ignored in Eclipse build in Eclipse references (experimental).
    This method would write above code between <lifecycleMappingMetadata> into workspace profile of lifecyclemapping into workspace/.metadata/.plugins/org.eclipse.m2e.core/lifecycle-mapping-metadata.xml
    This works in the entire workspace

Xiao
  • 12,235
  • 2
  • 29
  • 36
2

We have similar code generation under

<execution>
    <phase>generate-sources</phase>
    <goals>
        <goal>java</goal>
    </goals>
</execution>

And under plugins we also have additional entries to avoid eclipse complain

        <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.codehaus.mojo
                                    </groupId>
                                    <artifactId>
                                        exec-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [1.2.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>java</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution></pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>

Live example from GWT source code for lifecycle mapping- http://code.google.com/searchframe#T04cSGC7sWI/trunk/samples/expenses/pom.xml

Reference Explanation - stackoverflow.com/questions/6352208/how-to-solve-plugin-execution-not-covered-by-lifecycle-configuration-for-sprin

appbootup
  • 9,537
  • 3
  • 33
  • 65
  • I tried your code, but the errors still exists. I put them under the in the same pom.xml file as the exec plugin, is that right? – Xiao Nov 29 '12 at 02:50
  • Updated answer with link to sample pom from GWT source code. Also, read on reference explanation. – appbootup Nov 29 '12 at 04:44
  • Above code cannot deal with it. I read from http://wiki.eclipse.org/M2E_plugin_execution_not_covered and found `HINT: m2e provides a quick-fix associated with "plugin execution not covered" to easily create elements like above.` That helped me. I will take some snapshots to answer – Xiao Nov 29 '12 at 06:06
  • Oh, found it finally, this pom.xml is so long. And finally I know that your code must added inside ``, which is inside ``. If not, it would not work. And the wiki page named two methods. the quick fix one is the automatic way to add this code – Xiao Nov 29 '12 at 06:44
  • exactly :D . The devil always lies in the detail. GWT docs/example are improving ( but they are a long way off from being simple ) – appbootup Nov 29 '12 at 07:04