質問

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.

役に立ちましたか?

解決

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

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top