用gradle设置kotlin项目 [英] Setup kotlin project with gradle

查看:322
本文介绍了用gradle设置kotlin项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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

kotlin-gradle-plugin buildscript依赖只是Kotlin构建的Gradle插件,它不会为您的项目代码添加任何依赖项。



将以下内容添加到您的 build.gradle

 存储库{
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆