【问题标题】:IDEA showing a project twice in treeIDEA 在树中两次显示一个项目
【发布时间】:2016-03-22 13:53:29
【问题描述】:

我有一个带有两个孩子的 Gradle 的 Kotlin 项目。每当我尝试在 IDEA 中打开它时,其中一个孩子会在树中显示两次。

在树中,您可以在顶层看到两个项目,grpc 和 grp。问题是 grpc(从顶层)与作为 grp 子级的 grpc 是同一个项目。

这是我的 Gradle 构建文件:

父 gradle.build:

buildscript {
    ext.kotlin_version = '1.0.1'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
} 

gradle.settings 文件:

include ':grpstd', ':grpc'

grpc gradle.build:

apply plugin: 'antlr'
apply plugin: 'application'
apply plugin: 'kotlin'

mainClassName = 'sron.grpc.MainKt'

compileKotlin.dependsOn generateGrammarSource

generateGrammarSource {
    arguments += ['-package', 'sron.grpc.compiler.internal']
}

dependencies {
    antlr 'org.antlr:antlr4:4.5.2-1'

    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile 'commons-cli:commons-cli:1.3.1'
    compile 'org.ow2.asm:asm:5.0.4'
    compile project(':grpstd')

    testCompile 'junit:junit:4.12'
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}

grpstd gradle.build:

apply plugin: 'kotlin'

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    testCompile 'junit:junit:4.12'
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}

为什么该项目显示两次?我该如何预防?

【问题讨论】:

  • 我在 Groovy 项目中遇到了同样的问题。我相信这是由于自动导入,但还不知道任何解决方案。
  • 尝试删除 .gradle 文件夹,关闭项目并从 gradle 重新导入项目。
  • 当通过符号链接访问项目目录时,可能会发生这种情况。见stackoverflow.com/a/25888978/14379

标签: intellij-idea gradle kotlin


【解决方案1】:

打开您的project structure 对话框(您可以使用Ctrl+Alt+Shift+S),转到Modules 部分,检查您是否在那里定义了重复的模块。 如果有,请删除不必要的。

【讨论】:

    【解决方案2】:

    您可能想在导入 Gradle 模块时尝试禁用 为每个源集创建单独的模块选项。

    所以,完整的步骤是:

    1. 打开模块
    2. 移除 gradle 模块
    3. 重新导入模块。在导入向导的第二页上,确保禁用该选项:为每个源集创建单独的模块

    【讨论】:

    • 这不相关。 “模块”是指 IntelliJ 自己的模块结构(参见项目设置),而不是 Gradle 的。
    • 实际上为我解决此问题的选项就在您突出显示的选项上方:“使用显式模块组”
    猜你喜欢
    • 2020-02-22
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多