views:

2961

answers:

4

Can someone please recommend a GOOD online tutorial for writing maven2 plugins?

I looked at about 5 tutorials yesterday and each skipped steps, didn't tell you where key components (referenced in the tutorial) were supposed to go or how to install the plugin you wrote. Futher, many didn't reference which version of maven they worked with.

+6  A: 

Though not perfect I've got some good results from using the following Sonatype book: Maven: The Definitive Guide

Robert Nickens
Thanks for the link, Chapter 17 is where the goods are.
fooMonster
Two years later, it doesn't seem to help too much anymore. :(
Drew
A: 

The sonatype book seems to be really hyped. It has one small chapter for maven plugins and most of the time is wasted on explaining IOC (which every average developer knows about, courtesy Spring). All this chapter does is present a simple "Hello World" plugin where as any non trivial plugin will do a lot of other things.

Calm Storm
The initial cut of the book focused more on covering the basics of maven that were underserved by the existing docs. We do plan to add more chapters (and have since the printed book..the online version is updated regularly) but you're right, the plugin section is lacking currently. The sources are available for people to contribute, see here for more info: http://www.sonatype.com/people/2009/04/our-newest-open-source-project-maven-the-definitive-guide-part-2-of-2/
Brian Fox
+1  A: 

Try the maven mojo archetype or gmaven mojo archetype to create a sample plugin in Java or Groovy respectively. The source to a plugin is called a Mojo, just to help you navigate the terminology.

At a command prompt, type:

mvn archetype:generate

You'll get a menu of templates to choose from. Choose maven-archetype-mojo or gmaven-archetype-mojo

Using Java version: 1.6
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate]
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
11: internal -> maven-archetype-j2ee-simple (A simple J2EE Java application)
12: internal -> maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade)
13: internal -> maven-archetype-mojo (A Maven Java plugin development project)
14: internal -> maven-archetype-portlet (A simple portlet application)
15: internal -> maven-archetype-profiles ()
16: internal -> maven-archetype-quickstart ()
17: internal -> maven-archetype-site-simple (A simple site generation project)
18: internal -> maven-archetype-site (A more complex site project)
19: internal -> maven-archetype-webapp (A simple Java web application)
28: internal -> maven-archetype-har (Hibernate Archive)
29: internal -> maven-archetype-sar (JBoss Service Archive)
41: internal -> gmaven-archetype-basic (Groovy basic archetype)
42: internal -> gmaven-archetype-mojo (Groovy mojo archetype)
Choose a number:

Either of those will create a fully fleshed out Maven plugin example, ready to compile, install, and use.

Matthew McCullough
+2  A: 

I found this very simple introduction very useful. Though not complete it helps you getting started in a few minutes.

Yaba