我如何创建一个使用Gradle构建的Kotlin项目? [英] How can I create a Kotlin project that builds with Gradle?
问题描述
我正在尝试使用IntelliJ IDEA(Ubuntu 16.04上的2016.2.5)创建一个使用Gradle构建的新Kotlin项目。当我这样做时,我立即收到一条错误消息。
以下是我正在尝试的内容:
-
从左侧窗格Kotlin(Java)选择Gradle 从正确的。点击下一步。
-
输入hello-world作为ArtifactId。点击下一步。
确保从源集创建单独的模块和使用默认的Gradle包装器是
被选中,没有别的。点击下一步。 -
使用项目名称和位置的默认值。点击完成。
然后我马上得到这个错误:
Gradle'hello-world'项目刷新失败
错误:找不到org.jetbrains.kotlin:kotlin- gradle这个-插件:1.1 M02-12。
在以下位置搜索:
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
要求:
:hello-world:未指定
生成的 build.gradle
如下所示:
version'1.0-SNAPSHOT'
buildscript {
ext.kotlin_version ='1.1-M02-12'
知识库{
mavenCentral )
}
依赖项{
classpathorg.jetbrains.kotlin:kotlin-gradle-plugin:$ kotlin_version
}
}
申请插件:'kotlin'
仓库{
mavenCentral()
}
依赖关系{
compileorg.jetbrains.kotlin :KO tlin-stdlib:$ kotlin_version
如何创建一个构建的Kotlin项目与Gradle正确吗?
build.gradle
中,将 ext.kotlin_version
为: ext.kotlin_version ='1.1-M02 '
IDE插件将自己的版本放入构建脚本是一个小错误,而不是Kotlin版本。
还要将
存储库{
//。 ..
maven {urlhttp://dl.bintray.com/kotlin/kotlin-eap-1.1}
}
与EAP版本相关的Kotlin工件没有像公共版本那样放入Maven Central,并且这个库不会自动添加到生成的构建脚本中。
然后刷新Gradle项目,并且构建应该通过。
请随时与 build.gradle
文件。
I'm trying to create a new Kotlin project that builds with Gradle using IntelliJ IDEA (2016.2.5 on Ubuntu 16.04). When I do this I immediately get an error message.
Here's what I'm trying:
Select "Create New Project" from Welcome Screen.
Select "Gradle" from left hand pane, "Kotlin (Java)" from right. Click "Next".
Enter "hello-world" as ArtifactId. Click Next.
Ensure "Create separate module from source set" and "Use default Gradle wrapper" are selected, nothing else is. Click "Next".
Use defaults for project name and location. Click "Finish".
I then immediately get this error:
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
The generated build.gradle
looks like this:
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"
}
How can I create a Kotlin project that builds with Gradle correctly?
In your build.gradle
, change 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.
And also add the 1.1 EAP repository to the repositories
in both buildscript
and the root scope:
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.
Then refresh the Gradle project, and the build should pass.
Feel free to check with this build.gradle
file.
这篇关于我如何创建一个使用Gradle构建的Kotlin项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!