| 1 |
------------- |
| 2 |
ANTLR v4 Maven Plugin |
| 3 |
------------- |
| 4 |
Jim Idle |
| 5 |
------------- |
| 6 |
March 2009 |
| 7 |
------------- |
| 8 |
|
| 9 |
ANTLR v4 Maven plugin |
| 10 |
|
| 11 |
The ANTLR v4 Maven plugin is completely re-written as of version 4.0; if you are familiar |
| 12 |
with prior versions, you should note that there are some behavioral differences that make |
| 13 |
it worthwhile reading this documentation. |
| 14 |
|
| 15 |
The job of the plugin is essentially to tell the standard ANTLR parser generator where the |
| 16 |
input grammar files are and where the output files should be generated. As with all Maven |
| 17 |
plugins, there are defaults, which you are advised to comply to, but are not forced to |
| 18 |
comply to. |
| 19 |
|
| 20 |
This version of the plugin allows full control over ANTLR and allows configuration of all |
| 21 |
options that are useful for a build system. The code required to calculate dependencies, |
| 22 |
check the build order, and otherwise work with your grammar files is built into the ANTLR |
| 23 |
tool as of version 4.0 of ANTLR and this plugin. |
| 24 |
|
| 25 |
* Plugin Versioning |
| 26 |
|
| 27 |
The plugin version tracks the version of the ANTLR tool that it controls. Hence if you |
| 28 |
use version 4.0 of the plugin, you will build your grammars using version 4.0 of the |
| 29 |
ANTLR tool, version 4.2 of the plugin will use version 4.2 of the ANTLR tool and so on. |
| 30 |
|
| 31 |
You may also find that there are patch versions of the plugin such as 4.0-1 4.0-2 and |
| 32 |
so on. Use the latest patch release of the plugin. |
| 33 |
|
| 34 |
The current version of the plugin is shown at the top of this page after the <<Last Deployed>> date. |
| 35 |
|
| 36 |
|
| 37 |
* Default directories |
| 38 |
|
| 39 |
As with all Maven plugins, this plugin will automatically default to standard locations |
| 40 |
for your grammar and import files. Organizing your source code to reflect this standard |
| 41 |
layout will greatly reduce the configuration effort required. The standard layout lookd |
| 42 |
like this: |
| 43 |
|
| 44 |
+-- |
| 45 |
src/main/ |
| 46 |
| |
| 47 |
+--- antlr4/... .g4 files organized in the required package structure |
| 48 |
| |
| 49 |
+--- imports/ .g4 files that are imported by other grammars. |
| 50 |
+-- |
| 51 |
|
| 52 |
If your grammar is intended to be part of a package called <<<org.foo.bar>>> then you would |
| 53 |
place it in the directory <<<src/main/antlr4/org/foo/bar>>>. The plugin will then produce |
| 54 |
<<<.java>>> and <<<.tokens>>> files in the output directory <<<target/generated-sources/antlr4/org/foo/bar>>> |
| 55 |
When the Java files are compiled they will be in the correct location for the Javac |
| 56 |
compiler without any special configuration. The generated java files are automatically |
| 57 |
submitted for compilation by the plugin. |
| 58 |
|
| 59 |
The <<<src/main/antlr4/imports>>> directory is treated in a special way. It should contain |
| 60 |
any grammar files that are imported by other grammar files (do not make subdirectories here.) |
| 61 |
Such files are never built on their own, but the plugin will automatically tell the ANTLR |
| 62 |
tool to look in this directory for library files. |