Building Jenkins with Eclipse and m2e plug-in

Yesterday I finally managed to build Jenkins using Eclipse and m2e plug-in. With Eclipse Indigo release came a new version of the Maven plug-in for Eclipse (former M2Eclipse), m2e. Since I started using Eclipse Indigo and this new plug-in I hadn't been able to build Jenkins in Eclipse anymore.

I've been having a terrible fever and thought that it would be a good thing to stop playing Minecraft for a while and find a way to build Jenkins in Eclipse + m2e :-).

1. Maven Plug-ins execution in project life cycle

The first thing I've noticed were the messages regarding the execution of some Maven plug-ins in the project life cycle. m2e delegates the execution of Maven plug-ins to an external executor. As not all Maven plug-ins have an existing executor for m2e you will receive a message similar to "Plugin execution not covered by lifecycle configuration: ...".

The solution for this issue was adding a rule for each plug-in execution. This rule must contain a version or version range and declare whether this plug-in execution must be executed or ignored by m2e. You have two ways of adding these rules. You could a) Google for an example, b) replace group, artifact name and version. Or you could a) open pom.xml and select the tab "pom.xml" (this will open the XML source of your pom.xml) b) go to the line marked with an error in Eclipse, leave your mouse pointer over it and select the option "Permanently mark goal...", choose the parent pom.xml (jenkins/pom.xml) and save all documents.

<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>build-helper-maven-plugin</artifactid>
            <versionrange>[1.7,)</versionrange>
            <goals>
              <goal>timestamp-property</goal>
              <goal>regex-property</goal>
            </goals>
         </pluginexecutionfilter>
         <action>
           <execute />
         </action>
       </pluginexecution>
       <!-- other plug-ins... --->
     </pluginexecutions>
   </lifecyclemappingmetadata>
  </configuration>
</plugin>

2. Conflicting Maven repository ids

Another problem building Jenkins in Eclipse was that as there were SNAPSHOT dependencies in jenkins/pom.xml a snapshots repository was added with the id maven.jenkins-ci.org. This is the same repository id used in some tutorials to build Jenkins plug-ins. Thus, Maven will ignore this repository, using the one from settings.xml.

The solution for this issue was changing the repository id from maven.jenkins-ci.org to maven.jenkins-ci.org-snapshots.

<repository><!-- only until we release ant and javadoc plugins -->
  <id>maven.jenkins-ci.org-snapshots</id>
  <url>http://maven.jenkins-ci.org/content/repositories/snapshots/</url>
  <releases>
    <enabled>false</enabled>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>
<snapshotRepository>
  <id>maven.jenkins-ci.org-snapshots</id>
  <url>http://maven.jenkins-ci.org:8081/content/repositories/snapshots</url>
</snapshotRepository>

3. maven-localizer-plugin

This issue was related to the generation of the localization Java classes. maven-localizer-plugin reads properties files and generates Java classes with the text in a locale to be used by the plug-in. But sometimes Eclipse doesn't include all the source folders generated by this plug-in, causing the project to have compilation errors.

The solution for this issue was to add the generated sources manually in jenkins/pom.xml under the build-helper-maven-plugin plug-in configuration.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.7</version>
  <executions>
    <execution>
      <id>add-eclipse-sources</id>
      <phase>generate-sources</p<hase>
      <goals>
          <goal>add-source</goal>
      </goals>
      <configuration>
      <sources>
          <source>${basedir}/target/generated-sources/groovy-stubs/main</source>
          <source>${basedir}/target/generated-sources/localizer</source>
          <source>${basedir}/target/generated-sources/taglib-interface</source>
      </sources>
   </configuration>
  </execution>
  </executions>
</plugin>

Removing remaining Eclipse errors and warnings

Matthieu Vincent managed to overcome other Eclipse errors and warnings with the following steps:

Now you can follow the instructions in Jenkins Wiki for building Jenkins and have fun in your Eclipse. There still seems to have few issues to be solved. I can't see the version number in the footer, and the default plug-ins are missing. Time to go back to Minecraft now :D!

Cheers

Categories: Blog

Tags: Java, Jenkins