【问题标题】:Configure IntelliJ auto-completion for gradle script in kotlin在 kotlin 中为 gradle 脚本配置 IntelliJ 自动完成
【发布时间】:2016-12-22 08:09:55
【问题描述】:

我正在使用 IntelliJ 中的简单 hello-world 应用程序尝试 gradle-script-kotlin。但是 IntelliJ 自动完成不会在 build.gradle.kts 文件中弹出。

https://github.com/gradle/gradle-script-kotlin/tree/master/samples/hello-world

build.gradle.kts:

apply<ApplicationPlugin>()

configure<ApplicationPluginConvention> {
    mainClassName = ".HelloWorld"
}

configure<JavaPluginConvention> {
    setSourceCompatibility(1.8)
    setTargetCompatibility(1.8)
}

repositories {
    jcenter()
}

dependencies {
    testCompile("junit:junit:4.12")
}

settings.gradle:

rootProject.buildFileName = 'build.gradle.kts'

我安装了 IntelliJ kotlin 插件和 gradle 插件并使用 gradle 3.0。示例应用程序使用 gradle 命令。

如何配置 IntelliJ 以启用 build.gradle.kts 文件的自动完成功能?

我正在使用带有 kotlin 插件版本的 IntelliJ 2016.2.2:1.0.3-release-IJ2016.1-120

【问题讨论】:

    标签: intellij-idea gradle kotlin


    【解决方案1】:

    尝试通过选择settings.gradle 重新导入项目。

    【讨论】:

      【解决方案2】:

      遇到了同样的问题。 Gradle 脚本 Kotlin 需要 IntelliJ Kotlin 插件的 1.1x 版本。

      按照以下步骤安装它:
      https://github.com/gradle/gradle-script-kotlin/tree/master/samples#install-idea-kotlin-plugin

      常规更新频道目前仅更新到 1.0.3x 版本。

      18/06 更新:
      github 自述文件已更新,包括:
      (Note: this version will not work with the official Gradle 3.0 release, stick to the official EAP 1.1 from JetBrains if you intend to use Gradle 3.0)

      如果您之前手动安装了 1.1.0-dev-2222 版本,请将其卸载并重新启动 IntelliJ。

      从 EAP 频道安装 1.1.x 版

      此版本适用于 Gradle 3.0 中的 Kotlin-Script。

      在 IntelliJ 中,按:
      Tools =&gt; Kotlin =&gt; Configure Kotlin Updates.
      选择
      Early Access Preview 1.1
      并按
      Check for updates now

      下载最新的插件。
      如果报错,重启IntelliJ,插件就安装好了。

      【讨论】:

      • 感谢您的回复。我曾尝试过,但在事件日志中出现ClassCastException: org.gradle.script.lang.kotlin.support.GradleKotlinScriptDependenciesResolver cannot be cast to org.jetbrains.kotlin.script.ScriptDependenciesResolver 异常。可能它也与 IntelliJ 版本有关。我正在使用 IntelliJ 2016.2.1
      【解决方案3】:

      我在 intellij 2.5 中使用 kotlin-plugin-1.1.0-dev-2222.zip 尝试了 gradle 3.1。它对我有用。

      这是我的 intellij 版本:
      IntelliJ IDEA 2016.2.5 构建 #IC-162.2228.15,于 2016 年 10 月 14 日构建 JRE:1.8.0_112-release-287-b2 x86_64 JVM:JetBrains s.r.o 的 OpenJDK 64 位服务器虚拟机

      以及步骤:

      1、下载https://github.com/gradle/gradle-script-kotlin/tree/master/samples中的kotlin-plugin-1.1.0-dev-2222.zip并在Idea中安装插件
      2、在Idea中创建一个gradle java项目,并选择使用gradle wrapper
      3、在终端项目目录下,使用“./gradlew wrapper --gradle-version=3.1”切换到gradle 3.1
      4、在项目根目录下创建文件“build.gradle.kts”
      5、在settings.gradle文件中添加rootProject.buildFileName = 'build.gradle.kts'
      6、在build.gradle.kts中添加代码,如果自动补全不起作用,请在Gradle工具窗口中尝试“刷新所有项目”。
      7、如果还是不行,重启你的Idea

      这里是一个 github 仓库:https://github.com/kolyjjj/gradle-kotlin-test

      【讨论】:

        猜你喜欢
        • 2020-01-18
        • 2019-11-09
        • 1970-01-01
        • 1970-01-01
        • 2012-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多