通过Eclipse上的Gradle设置Kotlin [英] Kotlin setup via gradle on eclipse

查看:311
本文介绍了通过Eclipse上的Gradle设置Kotlin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

努力让Kotlin在日食上运行.

Struggling to get Kotlin running on eclipse.

我已经开始了新的Graddle项目.按照kotlin网站上的规定添加了依赖性.

I've started new graddle project. Added dependencies as prescribed on kotlin's site.

构建过程无误.

我已经在src/java/main下创建了"main.kt"文件:

I've created 'main.kt' file under src/java/main with:

fun main(args: Array<String>) {
    println("foo")
}

但是,我有两个问题: 1.科特林的任何东西println突出显示为未解决的参考". 2.我无法运行程序-Error: Could not find or load main class MainKt(右键单击以"kotlin应用程序"身份运行的main.kr)

BUT, I have two problems: 1. anything from kotlin e.g. println highlighted as 'unresolved reference'. 2. I can't run a program - Error: Could not find or load main class MainKt (rightclick on main.kr run as 'kotlin application')

如果我创建新科特林项目",则一切正常.

If I create 'new kotlin project' everything works.

我的gradle构建脚本:

my graddle build script:

plugins {
    id "org.jetbrains.kotlin.jvm" version "1.1.2-2"
}

repositories {

    jcenter()

    mavenCentral()
}


dependencies {

    //api 'org.apache.commons:commons-math3:3.6.1'


    implementation 'com.google.guava:guava:21.0'


    testImplementation 'junit:junit:4.12'

    compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.2-2"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8"

    compile "org.jetbrains.kotlin:kotlin-reflect"
    testCompile "org.jetbrains.kotlin:kotlin-test"
    testCompile "org.jetbrains.kotlin:kotlin-test-junit"

}

sourceSets {
    main.java.srcDirs = ['src/main/java']
    main.kotlin.srcDirs = ['src/main/java', 'src/main/kotlin']
    main.resources.srcDirs = ['src/main/resources']
}

我做错了什么?

如果这有帮助,我对Java的知识为零,所以我可能犯了一些小错误.

I've zero Java knowledge if that helps, so probably I've made some trivial error.

更新:

安装了一个Spring插件并通过它生成了一个新的Web应用程序,包括gradle. 但是科特林在那儿的举止也出乎意料.

Installed a Spring plugin and generated a new web app via it including gradle. But Kotlin behaves unpredictably there too.

起初,我无法以run as Kotlin application的身份运行它,并且找不到以main出现的错误,但有时它会运行并立即崩溃.在删除和编辑类之后,它开始启动并崩溃,尝试在其他程序包下创建它,然后删除并添加Kotlin(我无法重现序列以使其再次正常工作).

At first I was not able to run it as run as Kotlin application and it errored with main could not be found, BUT sometimes it run and crashed immediately. It started to launch and crash after I've deleted and edited classes, tried creating it under other package, removing and adding Kotlin (I can't reproduce sequence to make it work again).

gradle boot build的有趣部分启动了所有内容,并且一切正常运行,以某种方式找到了Kotlin的主要功能.

Fun part that gradle boot build launches everything and all works it somehow finds Kotlin's main.

Kotlin插件本身可能存在一些问题(其加载量取决于某些events并不总是触发)

Probably some issue with Kotlin plugin itself (it's load probably depends on certain events that doesn't always fire)

推荐答案

将以下内容添加到您的配置中:

Add the following to your configuration:

apply plugin: 'eclipse'
eclipse {
    classpath {
        containers 'org.jetbrains.kotlin.core.KOTLIN_CONTAINER'
    }
}

请参见 https://gitlab.com/frnck/kotlin-gradle-eclipse 进行有效的配置.

See https://gitlab.com/frnck/kotlin-gradle-eclipse for a working configuration.

这篇关于通过Eclipse上的Gradle设置Kotlin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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