我有一个项目,我想在一段 Kotlin 代码中使用由 ANTLR4 生成的类。
在pom.xml中,ANTLR4 配置如下。
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.7.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
生成的类被放入target/generated-sources/antlr4:
mvn clean package, mvn clean assembly, 以及在 Idea 中重建项目导致以下错误:
请注意,错误仅发生在 Kotlin 类Transpiler.kt中,而不发生在test中。
我该如何解决这个问题(确保 ANTLR4 生成的类可以在 Kotlin 代码中使用)?
更新1:按照@Bart Kiers 的建议移动语法文件并执行mvn clean antlr4:antlr4后,Idea 中的错误消失了。但是mvn clean antlr4:antlr4 install仍然会导致构建错误:
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.4.21:compile (compile) on project elispt: Compilation failure: Compilation failure:
[ERROR] /Users/dp118m/dev/misc/elispt/src/main/kotlin/com/dpisarenko/deplorable/Transpiler.kt:[9,21] Unresolved reference: DeplorableLexer
[ERROR] /Users/dp118m/dev/misc/elispt/src/main/kotlin/com/dpisarenko/deplorable/Transpiler.kt:[11,22] Unresolved reference: DeplorableParser
[ERROR] /Users/dp118m/dev/misc/elispt/src/main/kotlin/com/dpisarenko/deplorable/Transpiler.kt:[12,21] Unresolved reference: DeplorableParser

