未解决的参考:antlr

Unresolved reference: antlr

导入antlr时,如下图

import org.antlr.v4.runtime.*
...

我收到错误消息 Unresolved reference: antlr

不太确定您是否需要此信息,但我的 build.gradle 目前如下:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.6.10'
    id 'org.jetbrains.intellij' version '1.2.1'
    id 'java'
}

group 'me.ylee'
version '1.0-SNAPSHOT'

repositories {
    google()
    mavenLocal()
    mavenCentral()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
    implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.21"
    implementation "net.java.dev.jna:jna:5.11.0"
    // Dependency on local binaries
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

intellij {
    plugins = ['Kotlin', 'java']
}

compileKotlin {
    kotlinOptions.jvmTarget = '1.8'
}

compileTestKotlin {
    kotlinOptions.jvmTarget = '1.8'
}

如何才能成功导入antlr?我需要在 build.gradle 的某处包含 antlr 吗?

如有任何帮助,我们将不胜感激!

我想通了。我意识到我需要添加 antlr-related 依赖项,如修改后的 build.gradle 所示,如下所示:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.6.10'
    id 'org.jetbrains.intellij' version '1.2.1'
    id 'java'
    id 'antlr'
}

group 'me.ylee'
version '1.0-SNAPSHOT'

repositories {
    google()
    mavenLocal()
    mavenCentral()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
    implementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.21'
    implementation "net.java.dev.jna:jna:5.11.0"
    antlr 'org.antlr:antlr4:4.10.1'
    implementation 'org.antlr:antlr4-runtime:4.10.1'
    // Dependency on local binaries
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

intellij {
    plugins = ['Kotlin', 'java']
}

compileKotlin {
    kotlinOptions.jvmTarget = '1.8'
}

compileTestKotlin {
    kotlinOptions.jvmTarget = '1.8'
}