【发布时间】:2018-04-29 13:55:47
【问题描述】:
我正在使用Gradle 构建Kotlin 简单的Hello-Worl
我的build.gradle 是:
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.3.1/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Kotlin
apply plugin: 'kotlin'
/*
plugins {
id "org.jetbrains.kotlin.jvm" version "1.1.60"
}
*/
buildscript {
ext.kotlin_version = '1.1.60'
// In this section you declare where to find the dependencies of your project
repositories {
mavenCentral()
// jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.7'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile 'junit:junit:4.12'
}
kotlin {
experimental {
coroutines 'enable'
}
}
compileKotlin {
kotlinOptions.suppressWarnings = true
}
compileKotlin {
kotlinOptions {
suppressWarnings = true
}
}
而Main.kt 是:
fun main(args: Array<String>) {
println("kotlin!")
}
在运行Gradle buil 时,出现以下错误:
注意事项:
- 我是gradle 的新手,所以按照以下两个步骤构建它:
更新
根据第一个答案,我尝试在本地获取文件,我创建了另一个名为 lib 的文件夹并将 *.jar 文件下载到其中,所以我得到了 gradle.build 如下:
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
classpath fileTree(include: ['*.jar'], dir: 'libs')
classpath files('kotlin-gradle-plugin-1.1.60.jar')
}
}
apply plugin: 'kotlin'
sourceSets {
main.kotlin.srcDirs += 'src/kotlin'
main.resources.srcDirs += 'src/resources'
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.7'
compile name: 'kotlin-stdlib-1.1.60'
testCompile 'junit:junit:4.12'
}
kotlin {
experimental {
coroutines 'enable'
}
}
compileKotlin {
kotlinOptions.suppressWarnings = true
}
compileKotlin {
kotlinOptions {
suppressWarnings = true
}
}
我得到了修改后的结构和新错误:
更新
U 将所有需要的存储库 .jar 和 .pom 复制到文件夹:
C:\Users\.m2\repository\org\jetbrains\
我复制了例如: ...\kotlin\kotlin-std\1.1.60\kotlin-stdlib-1.1.60.jar 和 ...\annotations\13.0\annotations-13.0.jar
用过
mavenLocal()
但仍然遇到同样的错误:(
【问题讨论】:
标签: java maven gradle kotlin jcenter