用gradle设置kotlin项目 [英] Setup kotlin project with gradle
问题描述
我是kotlin和gradle的新手,并试图设置我的第一个项目:
uild.gradle
buildscript {
ext.kotlin_version ='1.0.1-1'
储存库{
mavenCentral()
bcenter()
}
依赖关系{
classpathorg.jetbrains.kotlin:kotlin-gradle-plugin:$ kotlin_version
}
}
应用插件:kotlin
src\main\kotlin \ main.kt
包hello
fun main(args:Array< String>){
println(Hello World!)
}
错误消息src\main\kotlin\main.kt:(4,4):Unresolved reference:println。
我复制的build.gradle文件从 http://kotlinlang.org/docs/reference/using-gradle.html
我会前标准库自动包含 - 还是我需要在这里添加一些东西?
我使用gradle 2.12,JDK 1.8。 (在这种情况下)
引用缺少 kotlin-stdlib $ c $依赖关系。它不会自动添加。
kotlin-gradle-plugin
buildscript依赖只是Kotlin构建的Gradle插件,它不会为您的项目代码添加任何依赖项。
将以下内容添加到您的 build.gradle $ c $中,以便使用标准库
存储库{
jcenter()
}
依赖关系{
compileorg.jetbrains.kotlin:kotlin-stdlib:$ kotlin_version
}
$ b $这些存储库 与
buildscript
中的不同)
I'm new to kotlin and gradle and tried to set up my very first project:
build.gradle
buildscript {
ext.kotlin_version = '1.0.1-1'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
src\main\kotlin\main.kt
package hello
fun main(args: Array<String>) {
println("Hello World!")
}
And I get the error message "src\main\kotlin\main.kt: (4, 4): Unresolved reference: println".
The build.gradle file I copied from http://kotlinlang.org/docs/reference/using-gradle.html
I'd expect that the standard libraries are included automatically - or do I need to add something here?
I'm using gradle 2.12, JDK 1.8. (in case this matters)
The reference is missing the kotlin-stdlib
dependency. It is not added automatically.
kotlin-gradle-plugin
buildscript dependency is only Gradle plugin for Kotlin builds, and it doesn't add any dependencies to your project code. In order to use the standard library, one should add it as a dependency.
Append the following to your build.gradle
:
repositories {
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
(jcenter()
is needed again, these repositories
are different from those in buildscript
)
这篇关于用gradle设置kotlin项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!