繁体   English   中英

在kotlin中为gradle脚本配置IntelliJ自动完成

[英]Configure IntelliJ auto-completion for gradle script in kotlin

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

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文件上启用自动完成?

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

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

请按照以下步骤进行安装:
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 Channel安装1.1.x版

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

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

下载最新的插件。
如果它出错,只需重新启动IntelliJ,它就会安装插件。

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

这是我的intellij版本:
IntelliJ IDEA 2016.2.5 Build#IC-162.2228.15,构建于2016年10月14日JRE:1.8.0_112-release-287-b2 x86_64 JVM:JetJrains sro的OpenJDK 64位服务器VM

步骤:

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 Tool窗口中尝试“刷新所有项目”。
7,如果仍然无法正常工作,请重启您的创意

这是一个github回购: https//github.com/kolyjjj/gradle-kotlin-test

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

暂无
暂无

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

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