user840718
user840718

Reputation: 1611

ANTLR4 doesn't work with custom configuration in Maven

I always used succesfully ANTLR4 combined with Maven inside Eclipse. I just want to change the default directory where I store my grammar, since I do not like the standard path which is src/main/antlr4. The issue of this path is the creation of a new java package, that I really do not want. So I simply decided to create another directory inside my project named grammar which contains another directory called imports. I did this following simply the website guidelines. Despite this, when I change the grammar it doesn't generate automatically the new sources, even with the maven commands!

So, this is my configuration file pom.xml:

<!-- ANTLR4 -->
        <plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>4.5.3</version>
            <executions>
                <execution>
                    <configuration>
                        <goals>
                            <goal>antlr4</goal>
                        </goals>
                        <libDirectory>grammar/imports</libDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>

Eclipse files

As you can see, the target directory is empty. Before this change, there was a generated-sources directory inside with all the .java files.

So, where is the error?

Upvotes: 1

Views: 977

Answers (1)

viniciusartur
viniciusartur

Reputation: 161

The correct way is:

<!-- ANTLR4 -->
        <plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>4.5.3</version>
            <executions>
                <execution>
                        <goals>
                            <goal>antlr4</goal>
                        </goals>
                        <configuration>
                            <libDirectory>grammar/imports</libDirectory>
                        </configuration>
                </execution>
            </executions>
        </plugin>  

The <configuration> tag must be at same level than <goals> tag, inside <execution> tag, according to Maven documentation: https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag and https://maven.apache.org/guides/mini/guide-default-execution-ids.html

In fact, the documentation in ANTLR4 Maven plugin is wrong: http://www.antlr.org/api/maven-plugin/latest/examples/libraries.html

Upvotes: 2

Related Questions