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

我正在用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文件自动完成?

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

有同样的问题。 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 => 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:由JetBrains提供的OpenJDK 64位服务器VM

和步骤:

1,在https://github.com/gradle/gradle-script-kotlin/tree/master/samples下载kotlin-plugin-1.1.0-dev-2222.zip并在Idea中安装插&#x4EF6;
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重新导入项目。