Detailed Usage

Pom.xml

In project's pom.xml or in parent's pom.xml:
- manage versions of the plugin and of the dependencies (the processors artifacts)
- if advantageous configure default values for common arguments for different executions

<?xml version="1.0" encoding="UTF-8"?>
...
  <properties>
    <!-- adapt versions -->
    <!-- run mvn versions:display-property-updates to display available updates -->
    <javacc.maven.plugin.version>3.8.0</javac.cmaven.plugin.version>
    <javacc.core.version>8.1.0</javacc.core.version>
    <javacc.cpp.version>8.1.0</javacc.cpp.version>
    <javacc.csharp.version>8.1.0</javacc.csharp.version>
    <javacc.java.version>8.1.0</javacc.java.version>
    <jtb.version>1.5.3</jtb.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
...
    <pluginManagement>
      <plugins>
...
        <plugin>
          <groupId>org.javacc.plugin</groupId>
          <artifactId>javacc-maven-plugin</artifactId>
          <version>$\{javacc.maven.plugin.version\}</version>
          <dependencies>
            <!-- declare all used generators artifacts;
                 the core may be omitted, as it is a dependency of the generators
                  (but is required if only jjdoc is used) -->
            <!--            <dependency>-->
            <!--              <groupId>org.javacc</groupId>-->
            <!--              <artifactId>core</artifactId>-->
            <!--              <version>${javacc.core.version}</version>-->
            <!--              <scope>runtime</scope>-->
            <!--            </dependency>-->
            <dependency>
              <groupId>org.javacc.generator</groupId>
              <artifactId>java</artifactId>
              <version>${javacc.java.version}</version>
              <scope>runtime</scope>
            </dependency>
            <dependency>
              <groupId>org.javacc.generator</groupId>
              <artifactId>csharp</artifactId>
              <version>${javacc.csharp.version}</version>
              <scope>runtime</scope>
            </dependency>
            ...
          </dependencies>
        </plugin>
        
      </plugins>
    </pluginManagement>
...
    <plugins>
...
      <plugin>
        <groupId>org.javacc.plugin</groupId>
        <artifactId>javacc-maven-plugin</artifactId>
        <!-- default values for common arguments for different executions  -->
        <configuration>
          <javaccCmdLineArgs>
            <enc>-GRAMMAR_ENCODING="UTF-8"</enc>
            <jjod>-OUTPUT_DIRECTORY="${project.build.directory}/generated-sources/javacc"</jjod>
          </javaccCmdLineArgs>
          <jjtreeCmdLineArgs>
            <jjtod>-JJTREE_OUTPUT_DIRECTORY="${project.build.directory}/generated-sources/jjtree"</jjtod>
          </jjtreeCmdLineArgs>
        </configuration>
      </plugin>
...
    </plugins>
...

In project's pom.xml:
- configure one or more executions, depending on the sets of grammars

...
    <plugins>
...
      <plugin>
        <groupId>org.javacc.plugin</groupId>
        <artifactId>javacc-maven-plugin</artifactId>
        <executions>
          <!-- as many executions as different sets of grammars similar configurations -->
          <!-- here we use a non standard layout: 
                ("my cc" and "gen-src" instead of "src" and "generated-sources") -->
          <execution>
            <id>jjtree-javacc</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>jjtree-javacc</goal>
            </goals>
            <configuration>
              <includes>
                <include>...</include>
              </includes>
              <excludes>
                <exclude>...</exclude>
              </excludes>
              <keepIntermediateDirectory>false</keepIntermediateDirectory> <!-- the default -->
              <skip>false</skip> <!-- the default -->
              <sourceDirectory>my cc</sourceDirectory>
              <jjtreeCmdLineArgs>
                <!-- overrides parent's one -->
                <jjtod>-JJTREE_OUTPUT_DIRECTORY="${project.build.directory}/gen-src/jjtree"</jjtod>
                <!-- additional arguments not in parent -->
                <arg>-CODE_GENERATOR="Java"</arg>
                <arg>-MULTI=true</arg>
              </jjtreeCmdLineArgs>
              <javaccCmdLineArgs>
                <!-- overrides parent's one -->
                <jjod>-OUTPUT_DIRECTORY="${project.build.directory}/gen-src/javacc"</jjod>
                <!-- additional arguments not in parent -->
                <arg>-CODE_GENERATOR="Java"</arg>
                <arg>-STATIC:false</arg>
              </javaccCmdLineArgs>
            </configuration>
          </execution>
        </executions>
      </plugin>
...
    </plugins>
...

Next run your build:

mvn generate-sources

or

mvn clean install

and, if you want it and if BNF reports are configured, generate your site:

mvn site

Examples

See the different pom.xml in the integration tests projects under /src/it for simpler or more complex examples.

Note that they all inherit from a parent pom /src/it/pom.xml (that itself does not inherit from a parent).

Debug

You can enable the plugin's debug mode by passing the SLF4J managed environment variable org.slf4j.simpleLogger.log.org.javacc.mojo set to debug:

mvn generate-sources -Dorg.slf4j.simpleLogger.log.org.javacc.mojo=debug

Parameters

The mojos' parameters are described under each mojo; there are also additional explanations in the README, especially on inheritance and overriding of parent's parameters.