As a part of Nectar, we are trying to build a custom language using ANTLR. Since our project uses maven during the build time, we have to integrate ANTLR with maven. Though ANTLR provides maven plug-in, its little tricky to use. So, in this post I am explaining the steps to integrate ANTLR with maven using ANTLR3 maven plug in.

###Step 1

You have to put all your grammar files , aka .g files in the default directory required by the plugin. Custom placing will not work because of some bug in the plugin. Hence, place the .g file in the following manner:


So the “required-package” is the package you specified in the .g file.

###Step 2

Add the plug-in to the pom as follows:


We added a configuration which generates the lexer and parser files in the src directory rather than the default generated source in target.

For more information about the plug-in, refer here

###Step 3

Just run the pom and your .g will be compiled successfully.