Guide to generating sources

Let's run though a short example to try and help. To generate sources you must first have a plugin that participates in the generate-sources phase like the Antlr plugin:

 * Generates files based on grammar files with Antlr tool.
 * @goal generate
 * @phase generate-sources
 * @requiresDependencyResolution compile
 * @author <a href="">Vincent Siveton</a>
 * @version $Id$
public class AntlrPlugin
    extends AbstractAntlrMojo
     * @see org.apache.maven.plugin.Mojo#execute()
    public void execute()
        throws MojoExecutionException

The first two lines say "I want to be fit into the generate-sources phase and my 'handle' is generate".

So this is all fine and dandy, we have a plugin that wants to generate some sources from a Antlr grammar but how do we use it. You need to specify that you want to use it in your POM:


If you then type "mvn compile" Maven will walk through the lifecycle and will eventually hit the generate-sources phase and see you have a plugin configured that wants to participate in that phase and the Antlr plugin is executed with your given configuration.