Skip to main content

Developing plugins for Hudson just got easier

Posted by kohsuke on November 13, 2006 at 12:03 PM PST

Over the weekend I switched the build of Hudson to Maven from Ant, for the goal of making plugin development a whole lot easier. Writing a plugin for Maven was really painful, but I'm hoping that I achieved the original goal.

The first step of developing a plugin would be to install a necessary Maven plugin on your system. In theory, this shouldn't be needed — Maven is supposed to download a plugin when you use it for the first time, but because of a bug, this doesn't happen. So you'd have to run the following command to do it.

$ cd /tmp
$ wget*checkout*/hudson/hudson/tools/bootstrap/pom.xml
$ mvn package
$ rm pom.xml

Then you can tell Maven to create a new plugin workspace like this (and I won't mention handful bugs and missing features that I had to work around in doing this — and I still can't figure out how to let Maven choose the latest available version of this plugin so that you won't need to say '1.2'):

$ mvn

You can then have maven generate IntelliJ project files or Eclipse project files. I've heard that NetBeans has its own module that lets you handle Maven projects natively.

Then the best part. To run your plugin in a debugger, you'll only need to do:

$ export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000"
$ mvn hpi:run

This will launch Hudson and your plugin Jetty, with everything set up. Changes to class files or other resources will be picked up automatically and you can get almost real time feedback on your change. This kind of set up is very hard to do in Ant, but it's so much easier with Maven.

Similarly, when you are ready to ship the plugin or use in the production environment, you can just run the following command to
create a distribution package. Compare that with the amount of build script you need to write with Ant.

$ mvn package

One of the strengths of Hudson is that a plugin can very seamlessly extend the core functionality. The truth is that every project has its own particular needs, and so the ability to be able to write a plugin to meet such custom needs is critical for a CI system. I'm hoping this simplified development model makes more people interested in writing plugins.

If you are interested in more about this, please take a look at "developing on Hudson" section of the project page, and drop us a note so that we can help you.

P.S. I wish Maven guys have documented their code more seriously, and spent a bit more time fixing bugs before moving on to other projects. I think I spent more time reading Maven code and searching for their mail archive, than to actually write my plugin code. And the worst part is that some of those problems leak through to my users!

Related Topics >>