Jenkins : Jenkins plugin development with Eclipse

This page collects common pitfalls and solutions for problems you may encounter while developing Jenkins plugins in Eclipse. See Plugin tutorial#Eclipse for the recommended way of using Eclipse.

Plugin execution not covered by lifecycle configuration

When you import a Jenkins plugin project with m2e, you might see a number of errors reporting "Plugin execution not covered by lifecycle configuration". This is because m2e wants to know how to deal with additional Maven plugins we use for building Jenkins plugins. If you are curious, see the write-up from m2e developers as to why they did this.

There are two ways to resolve this problem.

Upgrade to m2e 1.1+ and use maven-hpi-plugin 1.87+

m2e 1.1 introduced a mechanism to allow Maven plugins to define how the plugins should be handled by m2e. maven-hpi-plugin 1.87 contains this definition, thereby avoding the errors. To resolve the problem in this manner, you need to use m2e 1.1 and newer AND you need to use maven-hpi-plugin 1.87 and newer.

Beware that certain versions/editions of Eclipse bundles m2e by default, in those cases you cannot upgrade m2e by itself. It is probably simpler to just upgrade to Juno or later.

To use a newer version of maven-hpi-plugin, either ensure that you are building your plugin against sufficiently newer version of Jenkins (such as the current LTS base 1.509) or explicitly add the following fragment in your plugin pom.xml. If you grep the console output from Maven with "maven-hpi-plugin", you can see the current version you are using.

Use quick fix to ignore the errors

If the above approach isn't an option, you can right click those error messages and select quick fixes to shut m2e up.

Unable to find a plugin class. Did you put @plugin in javadoc?

If you get the error message Unable to find a plugin class. Did you put @plugin in javadoc? this maybe caused by Eclipse and Maven both using the target folder for build output. Run mvn clean install to let Maven rebuild the tree.

Messages cannot be resolved

If you see your Eclipse reporting that the "Messages" classes do not exist, make sure Eclipse is treating your target/generated-sources/localizer directory as one of the source root directory. If not, click this folder in the package explorer and add it from the context menu by following "Build Path > Use as Source Folder"

Unbound Classpath Variable M2_REPO in Eclipse

To fix this issue:

  • Open the Eclipse Preferences menu [Window - Preferences]
  • Got to [Java - Build Path - Classpath Variables]
  • Click 'New' and set its name as M2_REPO
  • Click 'Folder' and select your Maven repository folder.

This is normally in your home folder in '.m2/repository'

Only a type can be imported. <class> resolves to a package

Eclipse versions between 4.5 and < 4.6.2 contain a bug that causes errors such as "Only a type can be imported. hudson.model.Job resolves to a package".
If you encounter this error please upgrade to Eclipse Neon.2 (4.6.2) or higher (Bug 495598).