Search code examples
eclipsemavenm2eclipse

Set maven goal during import to Eclipse


In my Java project I generate a lot of source files from IDL files by idlj-maven-plugin. It works well - it generates files before compilation when, for example, I run compile goal in Eclipse. However, I wonder if it possible to generate source files when someone imports my project in Eclipse. I mean, I would like to achieve the last step in the following scenario:

  • someone clones project
  • imports that project using Import the Existing Maven project
  • after the above step the source files should be already generated so the user will not be confused by lack of those files (for example for a person who is not very familiar with maven and don't know that s/he needs to run goal maven to generate those files).

In the M2Eclipse description there is a statement that suggest that it is possible to set goals when projects are imported. I was looking for information about how to configure M2Eclipse to do that but with no luck.


Solution

  • I haven't used the idlj-maven-plugin myself, but we tweaked the regular "ignore-eclipse-mapping"-plugin configuration for another custom plugin we developed for our in-house needs:

    <pluginManagement>
      <plugins>
        <plugin>
         <groupId>org.eclipse.m2e</groupId>
         <artifactId>lifecycle-mapping</artifactId>
         <version>1.0.0</version>
         <configuration>
           <lifecycleMappingMetadata>
             <pluginExecutions>
               <pluginExecution>
                 <pluginExecutionFilter>
                   <groupId>OUR_PLUGIN_GROUP_ID</groupId>
                   <artifactId>OUR_PLUGIN_ARTIFACT_ID</artifactId>
                   <versionRange>[2.3,)</versionRange> <!-- Or whatever -->
                   <goals>
                     <goal>generate</goal> <!-- Or whatever idlj needs -->
                   </goals>
                 </pluginExecutionFilter>
                 <action>
                   <!-- this is what decides if the plugin should run or not -->
                   <!-- Most often, you will have an <ignore/> tag instead. -->
                   <execute>
                     <runOnIncremental>false</runOnIncremental>
                   </execute >
                 </action>
               </pluginExecution>
             </pluginExecutions>
           </lifecycleMappingMetadata>
         </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    

    I think this link has some information about it.