【发布时间】:2021-01-19 20:05:24
【问题描述】:
我有一个project,我想在其中使用由 ANTLR4 在一段 Kotlin 代码中生成的类。
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 仍然会导致build errors:
[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
【问题讨论】:
-
假设 Maven 构建也失败了,我不认为这是一个 IDE 问题。看起来 Maven 需要与现在不同的配置。也许 Kotlin 源配置不正确。
标签: java maven kotlin intellij-idea antlr4