我正在尝试使用Eclipse和Maven开发一个ANTLR 4.9.2项目。我已经将我的pom.xml
配置为使用运行时和构建工具的正确版本:
<properties>
<maven.compiler.target>18</maven.compiler.target>
<maven.compiler.source>18</maven.compiler.source>
<antlr4.plugin.version>4.9.2</antlr4.plugin.version>
<antlr4.version>4.9.2</antlr4.version>
</properties>
<dependencies>
<!-- ANTLR 4 parser runtime -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${antlr4.version}</version>
</dependency>
<!-- ANTLR 4 parser generator tools -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr4.plugin.version}</version>
</dependency>
<!-- other irrelevant dependencies redacted -->
</dependencies>
<build>
<plugins>
<!-- build antlr4 grammars -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr4.plugin.version}</version>
<configuration>
<arguments>
<argument>-visitor</argument>
<!-- <argument>-Dlanguage=JavaScript</argument> -->
</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ensure antlr4 generated source is added to the build path -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/antlr4/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我还安装了ANTLR4IDE eclipse外接程序(在安装细节屏幕中报告为ANTLR 4 SDK 0.3.6.201611052310 antlr4ide.sdk.feature.group Edgar Espina
),以便在编辑.g4
文件时提供语法突出显示。
我遇到的问题是,每次修改文件时,都会出现在控制台窗口中:
ANTLR Tool v4.4 (C:\Users\user\AppData\Local\Temp\antlr-4.4-complete.jar)
KindModule.g4 -o C:\Users\user\git\kindtest3\target\generated-sources\antlr4\org\kindlang\kindtest3\grammar -listener -no-visitor -package org.kindlang.kindtest3.grammar -encoding UTF-8
BUILD SUCCESSFUL
Total time: 4 second(s)
运行项目测试时,错误消息ANTLR Tool version 4.4 used for code generation does not match the current runtime version 4.9.2
失败。
我试图在“properties / ANTLR4 / Tool”下禁用"Tool is activated“设置,但这似乎只会在当前会话中禁用它。当我重新启动Eclipse时,它又开始发生了。
(更新--实际上,属性对话框中似乎有一个bug :当我单击"apply & close“时,标题为"Error”的消息框将被简要显示,但在读取其内容之前消失)
如何永久防止使用错误版本的ANTLR的自动生成运行?
发布于 2022-10-22 21:19:11
通过直接编辑项目根目录下的com.github.jknack.antlr4ide.Antlr4.prefs
目录中的.settings
文件并将autobuilding=true
行更改为autobuilding=false
,我已经能够解决这个问题。
发布于 2022-10-22 20:13:50
不幸的是,我不能说一些关于Eclipse的事情。
我建议以正确的方式使用antlr4 4 maven-plugin,如下所示:
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
<configuration>
<visitor>true</visitor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
此外,使用build-helper-maven-plugin
的配置非常简单,因为antlr4-maven-plugin
正确地添加了要编译的信息。这意味着删除build-helper-maven-plugin
的整个配置和定义,因为根本不需要它。
另外,我建议升级到最新版本的antlr4-maven-plugin /运行时,目前的版本是4.11.1 .
我会在普通命令行上检查编译等。
https://stackoverflow.com/questions/74166147
复制相似问题