【问题标题】:Kotlin build gradle ~ dependencies resolves as type DependencyHandlerScorpe instead of KotlinDependencyHandlerKotlin build gradle ~ dependencies 解析为类型 DependencyHandlerScorpe 而不是 KotlinDependencyHandler
【发布时间】:2022-12-31 00:08:17
【问题描述】:

我目前在我的一个项目的build.gradle.kts 文件中观察到以下非常奇怪的行为:

基本上,我有两个模块,相同的导入在一个模块中有效,但在另一个模块中无效。经过仔细检查,我注意到我认为可能是问题的根源,但我不知道为什么会发生或如何应对。

我想要做的核心是让这个导入运行:

kotlin {
    [...]
    sourceSets {
        val commonMain by getting
            dependencies {
                implementation(Dependencies.eventBus)
            }
        [...]
        }
    }
}

在左侧的模块中,效果很好。但是,在右侧的模块中,它没有。我可以观察到的差异是,由于某些奇怪的原因,getting 在右侧以紫色而不是黄色语法突出显示,dependencies 的类型为 this: DependencyHandlerScope 而不是 this: KotlinDependencyHandler

现在真正奇怪的是:在它下面的下一个块 (commonTest) 中,它再次“正确”运行(如:就像在左侧模块中一样,导入工作的地方)。

这里发生了什么?这真的是我导入失败的原因吗?如果是这样,我该怎么办呢?

【问题讨论】:

    标签: kotlin gradle


    【解决方案1】:

    好吧,在我花了更多时间查看它之后,我发现了问题:在那个案例中,dependencies 块周围缺少一对花括号,所以它应该是这样的,从视觉上看非常相似,但在句法上显然有很大的不同:

    kotlin {
        [...]
        sourceSets {
            val commonMain by getting {
                dependencies {
                    implementation(Dependencies.eventBus)
                }
            }
            [...]
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-15
      • 2021-05-18
      • 2022-06-21
      • 2019-07-29
      • 2023-01-27
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 2017-02-25
      相关资源
      最近更新 更多