简体   繁体   English

在 kotlin 上使用模块构建 gradle 脚本

[英]Build gradle script with modules on kotlin

I want to migrate from groovy to kotlin dsl in my gradle build script.我想在我的 gradle 构建脚本中从 groovy 迁移到 kotlin dsl。 I have 2 scripts in the project: build.gradle and publish-maven.gradle that attaches in the first one.我在项目中有 2 个脚本: build.gradle 和 publish-maven.gradle 附加在第一个脚本中。

For groovy I apply script so:对于 groovy 我应用脚本所以:

apply from: "${rootProject.projectDir}/publish-maven.gradle"

For kotlin I found the same code will be look like:对于 kotlin,我发现相同的代码如下所示:

apply(from = "publish-maven.gradle.kts")

But publish-maven.gradle.kts don't attaches to build.gradle.kts.但是 publish-maven.gradle.kts 不附加到 build.gradle.kts。 At the top of the script in IDE constantly hangs warning:在IDE中的脚本顶部不断挂起警告:

Code insight unavailable (configuration for this script wasn't received during the last Gradle project import)代码洞察不可用(上次 Gradle 项目导入期间未收到此脚本的配置)

and kotlin syntax don't recognized.并且无法识别 kotlin 语法。

I try also我也试试

apply(from = "${rootProject.projectDir}/publish-maven.gradle.kts")

or have found other examples but non of them helped.或者找到了其他例子,但没有一个有帮助。

What have I do to apply this script?我该怎么做才能应用这个脚本? Or the general question is how can I split build script into several files?或者一般问题是如何将构建脚本拆分为多个文件?

Gradle version: 6.7;摇篮版本:6.7; JDK: 1.8; JDK:1.8; IDE: IntellijIdea IDE:IntellijIdea

In my case, a fix for "Code insight unavailable" message in Intellij was to add references to my subprojects in settings.gradle.kts file.就我而言,Intellij 中“代码洞察不可用”消息的修复是在settings.gradle.kts文件中添加对我的子项目的引用。

I've tried to set a Gradle project with two subprojects: "app" and "core".我试图设置一个包含两个子项目的 Gradle 项目:“app”和“core”。 I didn't follow the examples correctly and I didn't include references in settings.gradle.kts .我没有正确地遵循示例,也没有在settings.gradle.kts包含引用。

settings.gradle.kts

rootProject.name = "MyProject"

include("app", "core") // <-- Line added

After reloading the Gradle project in the IDE, everything was fine.在 IDE 中重新加载 Gradle 项目后,一切正常。

While I might not be answering your question specifically (I'm sorry for that), this is one of very few results for searching "Code insight unavailable" in the search engine, so I hope someone will find this answer useful.虽然我可能没有专门回答你的问题(对此我很抱歉),但这是在搜索引擎中搜索“代码洞察不可用”的极少数结果之一,所以我希望有人会发现这个答案有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM