IntelliJ IDEA Gradle 项目无法识别/定位 Antlr 生成的源 [英] IntelliJ IDEA Gradle project not recognizing/locating Antlr generated sources

查看:74
本文介绍了IntelliJ IDEA Gradle 项目无法识别/定位 Antlr 生成的源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个简单的 Kotlin/Gradle 项目中使用 Antlr,当我的 Gradle 构建生成 Antlr 源时,它们无法导入到项目中.

I'm using Antlr in a simple Kotlin/Gradle project, and while my Gradle build is generating Antlr sources, they are not available for importing into the project.

如您所见(在左侧),正在生成类(词法分析器/解析器等).我还将这个 generated-src/antlr/main 目录配置为 Source Root.我看到的大多数问题都将此列为解决方案,但我已经这样做了.

As you can see (on the left), the classes (Lexer/Parser, etc.) are being generated. I have also configured this generated-src/antlr/main directory as a Source Root. Most questions I see list this as a solution, but I've already done it.

在多次重建(在 IDEA 和 CLI 中)并遵循所有常见的使缓存和重新启动"问题之后,问题仍然存在.

The issue persists after multiple rebuilds (both in IDEA and on the CLI), and following all the usual "Invalidate Cache and Restart" issues.

此外,CLI 上的 Gradle 版本中列出了导入问题,因此它似乎与 IDEA 无关.

Further, the import issue is listed in the Gradle build on the CLI so it doesn't seem isolated to IDEA.

我在这里遗漏了什么?

这是我最初创建项目时 IDEA 生成的 build.gradle 文件,以及 IDEA 用于项目/工作区同步的文件.

Here's the build.gradle file produced by IDEA when I was creating the project initially, and which IDEA is using for project/workspace synchronization.

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.2.50'
}

group 'com.craigotis'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

apply plugin: 'antlr'

dependencies {
    antlr "org.antlr:antlr4:4.5"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

推荐答案

尝试在idea 模块中添加生成的源代码,就像 Daniel Dekany 的这篇文章 这里:

Try to add generated sources in idea module like this post from Daniel Dekany here:

apply plugin: "idea"
...
sourceSets.main.java.srcDir new File(buildDir, 'generated/javacc')
idea {
    module {
        // Marks the already(!) added srcDir as "generated"
        generatedSourceDirs += file('build/generated/javacc')
    }
}

这篇关于IntelliJ IDEA Gradle 项目无法识别/定位 Antlr 生成的源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆