ANTLR4 不适用于 Maven 中的自定义配置

ANTLR4 doesn't work with custom configuration in Maven

我总是在 Eclipse 中成功使用 ANTLR4 和 Maven。 我只想更改存储语法的默认目录,因为我不喜欢 src/main/antlr4 的标准路径。这条路径的问题是创建一个新的 java 包,我真的不想要。 所以我只是决定在我的项目中创建另一个名为 grammar 的目录,其中包含另一个名为 imports 的目录。我只是按照网站指南这样做的。 尽管如此,当我更改语法时,即使使用 maven 命令,它也不会自动生成新源代码!

所以,这是我的配置文件 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>

如您所见,target 目录是空的。在此更改之前,内部有一个 generated-sources 目录,其中包含所有 .java 文件。

所以,错误在哪里?

正确的方法是:

<!-- 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>  

根据 Maven 文档,<configuration> 标签必须与 <goals> 标签处于同一级别,在 <execution> 标签内: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

其实ANTLR4 Maven插件中的文档是错误的: http://www.antlr.org/api/maven-plugin/latest/examples/libraries.html