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

查看:218
本文介绍了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.

如您所见(在左侧),正在生成类(Lexer/Parser等).我还将此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"
}

推荐答案

尝试在想法模块中添加生成的源,例如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天全站免登陆