我正在尝试创建一个新的 Kotlin 项目,该项目使用 IntelliJ IDEA(Ubuntu 16.04 上的 2016.2.5)通过 Gradle 构建。当我这样做时,我立即收到一条错误消息。
这就是我正在尝试的:
从欢迎屏幕中选择“创建新项目”。
从左侧窗格中选择“Gradle”,从右侧窗格中选择“Kotlin (Java)”。点击下一步”。
输入“hello-world”作为 ArtifactId。点击下一步。
确保“从源集中创建单独的模块”和“使用默认 Gradle 包装器”
选了,其他都没有了。点击下一步”。
使用项目名称和位置的默认值。单击“完成”。
然后我立即收到此错误:
Gradle 'hello-world' project refresh failed
Error: Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.1-M02-12.
Searched in the following locations:
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1-M02-12/kotlin-gradle-plugin-1.1-M02-12.pom
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1-M02-12/kotlin-gradle-plugin-1.1-M02-12.jar
Required by:
:hello-world:unspecified
生成的build.gradle
看起来像这样:
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1-M02-12'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
如何创建一个使用 Gradle 正确构建的 Kotlin 项目?
In your build.gradle
, 改变ext.kotlin_version
to be:
ext.kotlin_version = '1.1-M02'
It's a minor bug that the IDE plugin puts its own version into build scripts, not the Kotlin version.
并将 1.1 EAP 存储库添加到repositories
同时buildscript
和根范围:
repositories {
// ...
maven { url "http://dl.bintray.com/kotlin/kotlin-eap-1.1" }
}
Kotlin artifacts related to EAP versions are not put into Maven Central like those of public releases, and this repository is not added automatically into the generated build script.
然后刷新 Gradle 项目,构建应该会通过。
请随时查看this build.gradle file https://gist.github.com/h0tk3y/0112caf770d2d47bf9cf590c79ba225f.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)