Chase Burkel
Chase Burkel

Reputation: 31

Upgrading past ANTLR 4.5 no longer processes grammar in maven

I have 4 ANTLR parser/lexers (they are separate, so 8 total), and they were written in version 4.2. Recently, I have updated to the newest 4.9.2 release, but I noticed during a mvn clean install it no longer processes the grammars. I went ahead and removed my generated .java parsers/lexers thinking it would acknowledge they were missing and regenerate them, but it did not and ended up failing the build due to test errors since they were missing.

It looks like this (issue?) starts after version 4.5, once I upgrade past there it no longer processes my grammars during a mvn clean install. Is there an additional parameter I need to specify this? Below is my antlr4 plugin in my pom.xml:

         <plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>4.5</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sourceDirectory>${project.basedir}/src/main/java/ast</sourceDirectory>
                        <outputDirectory>${project.basedir}/src/main/java/ast</outputDirectory>
                        <timestamp>false</timestamp>
                        <listener>false</listener>
                        <visitor>true</visitor>
                    </configuration>
                    <goals>
                        <goal>antlr4</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Edit: When running a version past 4.5, there is no error, it just simply states the following:

--- antlr4-maven-plugin:4.7:antlr4 (default) @ projectname --- No grammars to process

ANTLR 4: Processing source directory C:\Users...directory...\src\main\java\ast

Upvotes: 2

Views: 1009

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170278

This works for me:

<project ... >

    ...

    <build>
        <plugins>
            <plugin>
                <groupId>org.antlr</groupId>
                <artifactId>antlr4-maven-plugin</artifactId>
                <version>4.9.2</version>
                <configuration>
                    <arguments>
                        <argument>-visitor</argument>
                    </arguments>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>antlr4</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

With folder structure:

src/
  main/
    antlr4/
      yourpackage/
        YourGrammar.g4

the generated Java classes for the *.g4 grammars will be generated in: ./target/generated-sources/antlr4/yourpackage

Upvotes: 0

Related Questions