0
votes

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

1
what is the error though?fukanchik
@fukanchik No error, it just simply says "No grammars to process"Chase Burkel
First follow the convention over configuration paradigm. This means put the grammar you would like to translate into src/main/antl4 Remove the configuration sourceDirectory and outputDirectory from your configuration...khmarbaise
@fukanchik I hadn't seen this, but it did not seem to fix my problem.Chase Burkel

1 Answers

0
votes

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