|
This document, together with the hello-world plugin, shows you how to get started with the plugin development. What Can Plugins Do?Hudson defines extensibility points, which are interfaces or abstract classes that model an aspect of a build system. Those interfaces define contracts of what need to be implemented, and Hudson allows plugins to contribute those implementations. See this document for more about extension points. In this document, we'll be implementing a Builder that says hello. (built-in builders include Ant, Maven, and shell script. Builders build a project.) Other resourcesBesides this tutorial, there are other tutorials and examples available on line:
Setting Up EnvironmentTo develop a plugin, you need Maven 2 (why?) and JDK 5.0 or later. If this is the first time you use Maven, make sure Maven can download stuff over the internet. Next, you'll have to have Maven download the necessary tools for you. Create an empty directory, download this pom.xml in there, and run "mvn package". This should download a bunch of tools. $ cd /tmp $ wget https://hudson.dev.java.net/source/browse/*checkout*/hudson/trunk/hudson/tools/bootstrap/pom.xml $ mvn package $ rm pom.xml Finally, add the following to your ~/.m2/settings.xml (Windows users will find them in c:\Documents and Settingsyourname\.m2\settings.xml): <settings>
...
<pluginGroups>
...
<pluginGroup>org.jvnet.hudson.tools</pluginGroup>
</pluginGroups>
Also, if your Maven has trouble resolving artifacts, consider adding the following entries to your ~/.m2/settings.xml too. This is a crude way to cause Maven to look at the java.net m2 repository all the time for artifact resolutions. <settings>
...
<profiles>
...
<profile>
<id>hudson</id>
...
<repositories>
...
<repository>
<id>java.net2</id>
<url>http://download.java.net/maven/2</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>hudson</activeProfile>
</activeProfiles>
</settings>
Creating a New PluginTo start a new plugin, run the following maven command: $ mvn org.jvnet.hudson.tools:maven-hpi-plugin:1.20:create This will ask you a few question, like the groupId (the maven jargon for the package name) and the artifactId (the maven jargon for your project name), then create a skeleton plugin from which you can start with. Make sure you can build this: $ cd newly-created-directory $ mvn package You should then generate IDE project files, so that you can develop a plugin productively. // if you are using IntelliJ $ mvn -DdownloadSources=true idea:idea // if you are using Eclipse $ mvn -DdownloadSources=true eclipse:eclipse NetBeans users should consider using this NetBeans module. Due to a bug in Eclipse, Eclipse users will need to remove src/main/resources from the source folder list after projects are imported to the workspace. See this e-mail thread for more details. At this point, from your IDE, you should be able to see all files and all the needed libraries complete with their source code. 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 use the target folder for build output. Plugin Workspace LayoutThe plugin workspace consists of the following major pieces: pom.xmlMaven uses it for building your pluginsrc/main/javaJava source files of the plugin src/main/resourcesJelly/Groovy views of the plugin. See this document for more about it. src/main/webappStatic resources of the plugin, such as images and HTML files. Source CodeLet's take a look at the source code. A plugin's main entry point is a PluginImpl class that extends from Plugin. Once Hudson detects your plugin (via its @plugin javadoc annotation — this gets copied into manifest during the build), it will create an instance, and invokes methods. Most of the time, a plugin class just registers extension points. See the source code for more about how a Builder is implemented and what it does. Developing a PluginRun the following command to launch Hudson with your plugin: $ export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n" $ mvn hpi:run Windows: > set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n > mvn hpi:run If you open http://localhost:8080/ in your browser, you should see the Hudson page running in Jetty. The MAVEN_OPTS portion launches this whole thing with the debugger port 8000, so you should be able to start a debug session to this port from your IDE. Once this starts running, keep it running. Jetty will pick up all the changes automatically.
Changing portIf you need to launch the Hudson on a different port than 8080, set the port through the system property jetty.port $ mvn hpi:run -Djetty.port=8090 Distributing a PluginTo create a distribution image of your plugin, run the following Maven goal: $ mvn package This should create target/*.hpi file. Other users can use Hudson's web UI to upload this plugin to Hudson (or place it in $HUDSON_HOME/plugins.) Hosting a Plugin on java.netIf you got to this point, you should definitely consider hosting your plugin on java.net. Move on to this document for how to do that. Other Tips
|

Comments (29)
Jul 18, 2007
Anonymous says:
I think that the pom mentioned in this page is out of date. You will need to edi...I think that the pom mentioned in this page is out of date. You will need to edit it to have the following:
java.net
url = http://download.java.net/maven/1
java.net2
url = http://download.java.net/maven/2
Jul 23, 2007
Kohsuke Kawaguchi says:
Thanks. Fixed.Thanks. Fixed.
Jul 24, 2007
Stephen Connolly says:
We need to update the hpi plugin so that the httpPort bound during hpi:run is us...We need to update the hpi plugin so that the httpPort bound during hpi:run is user configurable form the command line.
E.g. something like
mvn hpi:run -DhttpPort=xxxx
As in some cases I already have a tomcat instance on 8080 that I'm not exactly keep to restart (as I'm doing hudson development while waiting for the tomcat instance to do some other stuff
Aug 04, 2007
Kohsuke Kawaguchi says:
Added https://hudson.dev.java.net/nonav/mavenhpiplugin/Added https://hudson.dev.java.net/nonav/maven-hpi-plugin/
Aug 20, 2007
Anonymous says:
Hi I followed the instructions and I got the following error when I tried 'mvn ...Hi -
I followed the instructions and I got the following error when I tried 'mvn package' in the project the hpi archetype created:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Internal error in the plugin manager executing goal 'org.jvnet.hudson.tools:maven-hpi-plugin:1.11:apt-compi
le': Unable to find the mojo 'org.jvnet.hudson.tools:maven-hpi-plugin:1.11:apt-compile' in the plugin 'org.jvnet.h
udson.tools:maven-hpi-plugin'
com/sun/mirror/apt/AnnotationProcessorFactory
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Mon Aug 20 22:25:53 PDT 2007
[INFO] Final Memory: 27M/64M
[INFO] ------------------------------------------------------------------------
Aug 21, 2007
Kohsuke Kawaguchi says:
Could you please file this as an issue in the issue tracker, and run the same wi...Could you please file this as an issue in the issue tracker, and run the same with "mvn -X" and attach the log file?
(You'd need to request the observer role in the project to do this — thanks!)
Aug 29, 2007
Anonymous says:
Hi, I followed your instructions (downloading Maven2, then getting the pom.xml a...Hi,
I followed your instructions (downloading Maven2, then getting the pom.xml and doing mvn package) but I can't modify the settings.xml... I don't have that file in my .m2 directory
Could you help?
Thanx
Sep 03, 2007
Frank LaFond says:
I was able to get past this point with the simple settings.xml file: <settings>...I was able to get past this point with the simple settings.xml file:
It worked for me.
Frank LaFond.
Nov 24, 2007
kleinmantara says:
I get the following error with the mavenhpiplugin version 1.11: E:\coder\hgsls\...I get the following error with the maven-hpi-plugin version 1.11:
But when i use maven-hpi-plugin version 1.14 it works. BTW it took 31 minutes 46 seconds.
Dec 12, 2007
Anonymous says:
Yo Kawaguchi... just have to say that Hudson's architecture (and your Stapler pr...Yo Kawaguchi... just have to say that Hudson's architecture (and your Stapler project) are just insanely elegant. High fives all around.
Dec 12, 2007
Mike Caron says:
Uh, yeah... I wasn't logged in. This is me.Uh, yeah... I wasn't logged in. This is me.
Feb 23, 2008
Matthew R Harrah says:
I got Maven 2.0.8 and installed it according to their directions, downloaded the...I got Maven 2.0.8 and installed it according to their directions, downloaded the pom.xml file into a new directory, and ran mvn package and got this error:
I also tried using a settings.xml file as described (the "crude" way) and got the same error. I am not behind any proxy.
Any ideas? Since I am new to Maven I am pretty sure its some dumb thing I'm doing....
Feb 24, 2008
Lyndon Washington says:
I got the same problem that Matthew did with version 2.08 of maven. I trie...I got the same problem that Matthew did with version 2.08 of maven. I tried going back to 2.04 and that did not seem to help.
Cheers!
Feb 24, 2008
Lyndon Washington says:
Oh never mind. I looked in the \/.m2/repository and found the version is 1...Oh never mind. I looked in the ~/.m2/repository and found the version is 1.17 at this point. Sorry!!
Feb 24, 2008
Matthew R Harrah says:
Turns out I was right. It was something dumb I was doing. My firewal...Turns out I was right. It was something dumb I was doing. My firewall software was not allowing java.exe to access the internet.
Feb 29
Anonymous says:
I want to download the source for a plugin and make a patch. But I can't e...I want to download the source for a plugin and make a patch. But I can't even get the source!
I'm behind a proxy that uses a username/password. I got Maven to download everything, but no source!
And then I tried checking it out of CVS and got this:
Any help?
Feb 29
Kohsuke Kawaguchi says:
The error message says it all. There's no such module `hudson/hudson/plugin/cobe...The error message says it all. There's no such module `hudson/hudson/plugin/cobertura'
You made a typo. It's "plugins".
Mar 04
Dan Lewis says:
I followed the instructions and I get the following error when I do mvn hp...I followed the instructions and I get the following error when I do mvn hpi:run:[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 1 seconds.
2008-03-04 13:15:12.765:/:INFO: Stapler: init
2008-03-04 13:15:12.781::WARN: EXCEPTION
javax.servlet.ServletException: there's no "app" attribute in the application context.
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:446)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:370)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:468)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1074)
at hudson.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:79)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1065)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:185)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:689)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:391)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:146)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:285)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:457)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:751)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:500)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:357)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:329)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)
I am using Maven 2.0.8, Java 1.6.0_02 on Windows XP Pro SP2. Am I doing something wrong? I am new to Maven.
Mar 13
Erling Linde says:
I have problems with external dependencies: I get lots of these: Caused by: java...I have problems with external dependencies:
I get lots of these: Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.sun.syndication.propono.atom.client.AtomClientFactory
I have referenced the libraries using Maven 2, e.g.:
<dependency>
<groupId>propono</groupId>
<artifactId>propono</artifactId>
<version>0.6</version>
</dependency>
The libraries are included in WEB-INF/lib
I have also tried putting the libraries in tomcat/lib and also tomcat/webapps/hudson/WEB-INF/lib
Where should external jars be put? How should they be referenced?
Thanks, Erling
Mar 23
turbouser says:
Any help is appreciated...How do I resolve the error? C:\Program Files\Apache So...Any help is appreciated...How do I resolve the error?
C:\Program Files\Apache Software Foundation\apache-maven-2.0.8\tmp>mvn package
[INFO] Scanning for projects...
Downloading: http://download.java.net/maven/1//org.jvnet.hudson.tools/poms/tools\-1.4.pom
Downloading: http://download.java.net/maven/2//org/jvnet/hudson/tools/tools/1.4/tools-1.4.pom
Downloading: http://download.java.net/maven/2/org/jvnet/hudson/tools/tools/1.4/tools-1.4.pom
Downloading: http://repo1.maven.org/maven2/org/jvnet/hudson/tools/tools/1.4/tools-1.4.pom
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: null:maven-hpi-plugin:maven-plugin:1.18
Reason: Cannot find parent: org.jvnet.hudson.tools:tools for project: null:maven
-hpi-plugin:maven-plugin:1.18 for project null:maven-hpi-plugin:maven-plugin:1.1
8
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Sun Mar 23 23:00:15 PDT 2008
[INFO] Final Memory: 1M/4M
[INFO] ------------------------------------------------------------------------
Mar 24
David Hayes says:
This is basically to do with the fact that the java.net maven source and the hud...This is basically to do with the fact that the java.net maven source and the hudson source are slightly out of sync. Not to worry, a simple fix locally will fix this:
Change the file:
c:\documents and settings\your user\.m2\repository\org\jvnet\hudson\tools\maven-hpi-plugin\1.18\maven-hpi-plugin-1.18.pom
(change this to whatever suits your operating system)
Right near the top of the file, you'll see the following block:
Change this to:
Note the change of the version number. Now try again, and everything should work!
Mar 25
turbouser says:
You were 100% right. Everything is working now. \Thanks.You were 100% right. Everything is working now. -Thanks.
Mar 28
Max Sauer says:
Thanks for this, the tools1.4.pom is not present inside repository. It would be ...Thanks for this, the tools-1.4.pom is not present inside repository. It would be fine to have a note in the tutorial above.
Mar 31
Kohsuke Kawaguchi says:
This is fixed now. In the future, please report these issues to the issue tracke...This is fixed now. In the future, please report these issues to the issue tracker, so that we can fix it, instead of asking everyone to work around the problem.
Apr 08
Wojtek Gworek says:
Can anybody send me pom.xml from https://hudson.dev.java.net/source/browse/check...Can anybody send me pom.xml from https://hudson.dev.java.net/source/browse/*checkout*/hudson/hudson/tools/bootstrap/pom.xml
Any time I try to access it I do see response about Unknown location: hudson/tools/bootstrap/pom.xml
Apr 08
Kohsuke Kawaguchi says:
Link fixed. This was due to CVS>SVN migration.Link fixed. This was due to CVS->SVN migration.
May 14
Munish Gopal says:
When i run mvn package command, I get this error: \INFO\ \hpi:aptcompile\ \INFO\...When i run mvn package command, I get this error:
[INFO] [hpi:apt-compile]
[INFO] Compiling 2 source files to /opt/setups/apache-maven-2.0.9/agitar/target/classes
[FATAL ERROR] org.jvnet.hudson.maven.plugins.hpi.AptMojo#execute() caused a linkage error (java.lang.NoClassDefFoundError) and may be out-of-date. Check the realms:
[FATAL ERROR] Plugin realm = app0.child-container[org.jvnet.hudson.tools:maven-hpi-plugin]
urls[0] = file:/root/.m2/repository/org/jvnet/hudson/tools/maven-hpi-plugin/1.20/maven-hpi-plugin-1.20.jar
urls[1] = file:/root/.m2/repository/org/apache/maven/maven-archiver/2.0.1/maven-archiver-2.0.1.jar
urls[2] = file:/root/.m2/repository/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar
urls[3] = file:/root/.m2/repository/org/codehaus/plexus/plexus-archiver/1.0-alpha-4/plexus-archiver-1.0-alpha-4.jar
urls[4] = file:/root/.m2/repository/org/mortbay/jetty/maven-jetty-plugin/6.1.1/maven-jetty-plugin-6.1.1.jar
urls[5] = file:/root/.m2/repository/commons-el/commons-el/1.0/commons-el-1.0.jar
urls[6] = file:/root/.m2/repository/org/mortbay/jetty/jetty/6.1.1/jetty-6.1.1.jar
urls[7] = file:/root/.m2/repository/org/mortbay/jetty/jetty-util/6.1.1/jetty-util-6.1.1.jar
urls[8] = file:/root/.m2/repository/org/mortbay/jetty/servlet-api-2.5/6.1.1/servlet-api-2.5-6.1.1.jar
urls[9] = file:/root/.m2/repository/org/apache/maven/maven-plugin-tools-api/2.0/maven-plugin-tools-api-2.0.jar
urls[10] = file:/root/.m2/repository/org/mortbay/jetty/jetty-plus/6.1.1/jetty-plus-6.1.1.jar
..............
.........
[FATAL ERROR] Container realm = plexus.core
urls[0] = file:/opt/setups/apache-maven-2.0.9/lib/maven-2.0.9-uber.jar
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] com.sun.tools.apt.Main
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NoClassDefFoundError: com.sun.tools.apt.Main
at org.jvnet.hudson.maven.plugins.hpi.AptCompiler.compileInProcess(AptCompiler.java:62)
at org.jvnet.hudson.maven.plugins.hpi.AptCompiler.compile(AptCompiler.java:50)
at org.jvnet.hudson.maven.plugins.hpi.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:486)
at org.jvnet.hudson.maven.plugins.hpi.CompilerMojo.execute(CompilerMojo.java:111)
at org.jvnet.hudson.maven.plugins.hpi.AptMojo.execute(AptMojo.java:21)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
I am struck at this point. Can anyone help?
May 14
Jeff Berkowitz says:
Munish, I take it from the appearance of codehaus in your stack backtrace that y...Munish, I take it from the appearance of codehaus in your stack backtrace that you may be using the "mevenide" plugin for netbeans. If so, please look at the email archives for the last few days at http://www.nabble.com/codehaus---mevenide-f11958.html because there appears to be a problem with the latest version of the plugin.
Jul 13
Michael Greifeneder says:
If you get an error like this: >mvn org.jvnet.hudson.tools:mavenhpiplugin:1.20:c...If you get an error like this:
>mvn org.jvnet.hudson.tools:maven-hpi-plugin:1.20:create
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.sun:tools:jar:1.5
You probably haven't set JAVA_HOME correctly.