Skip to content

Instantly share code, notes, and snippets.

@sharwell
Last active January 23, 2022 15:55
Show Gist options
  • Save sharwell/4979017 to your computer and use it in GitHub Desktop.
Save sharwell/4979017 to your computer and use it in GitHub Desktop.
Maven pom.xml to support automatic code generation for ANTLR 4 grammar(s) during an Eclipse build. This configuration does not support (and is not intended for) building using Maven alone.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.uiuc</groupId>
<artifactId>cchistory</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CodeCompletionWithHistory</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antlr4.visitor>true</antlr4.visitor>
<antlr4.listener>true</antlr4.listener>
</properties>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>2.1.0.201209190230-r</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>bin</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>6</source>
<target>6</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArguments>
<Xlint />
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/antlr4</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
<configuration>
<sourceDirectory>src</sourceDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<versionRange>[4.0,)</versionRange>
<goals>
<goal>antlr4</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@szerhusenBC
Copy link

szerhusenBC commented Apr 28, 2016

@Vadi: Don't use package declaration in grammar file and configure the antlr4-maven-plugin like this:

<configuration>
   <arguments>
      <argument>-package</argument>
      <argument>my.package.path</argument>
   </arguments>
</configuration>

@khmarbaise
Copy link

You shouldn't use build-helper-maven-plugin here, cause antlr4-maven-plugin already adds the sources to the compile roots.. Furthermore the life cycle mapping for m2e are not needed cause antlr4-maven-plugin (using newer version 4.5.X ?) already contains appropriate mapping in the plugin itself. So it shouldn't be necessary...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment