如何使用 Kotlin 和 Tornado FX 设置 Gluon 应用程序

How to set up a Gluon application with Kotlin and Tornado FX

我目前尝试结合以下技术:

问题是,我是 Intellij-IDEA 的新手,在正确设置它时遇到问题,尽管我认为 build.gradle 文件足够合适。

这是我的 build.gradle 到目前为止的样子:

buildscript {
    ext.kotlin_version = '1.0.6'

    repositories {
        jcenter()
        mavenCentral()
    }

    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'kotlin'
// apply plugin: 'com.android.application'
// apply plugin: 'kotlin-android'

repositories {
    jcenter()
    mavenCentral()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'eu.dzim.test.Main'

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    // compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    compile 'com.gluonhq:charm:4.2.0'
    compile 'no.tornado:tornadofx:1.5.9'
    compile 'no.tornado:tornadofx-controls:1.0.4'
}

jfxmobile {
    downConfig {
        version = '3.1.0'
        // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
}

我至少设法阻止了 IDE 对 Kotlin 的抱怨。我将一个简单的应用程序 class 转换为如下所示:

package eu.dzim.test

import com.gluonhq.charm.down.Platform
import javafx.application.Application
import javafx.scene.Scene
import javafx.scene.layout.BorderPane
import javafx.stage.Screen
import javafx.stage.Stage

/**
 * Created by daniel on 06.01.17.
 */
class Main : Application() {

    @Throws(Exception::class)
    override fun start(stage: Stage) {

        var width = -1.0
        var height = -1.0
        if (Platform.isDesktop()) {
            width = 480.0
            height = 640.0
            stage.title = "Test"
        }
        val primaryScreen = Screen.getPrimary()
        val visualBounds = primaryScreen.visualBounds
        if (width < 0 || height < 0) {
            width = visualBounds.width
            height = visualBounds.height
        }

        val root = BorderPane()

        val scene = Scene(root, width, height)

        stage.scene = scene

        stage.show()
    }
}

但现在我卡住了,因为对 Tornado FX 的依赖没有正确解决。 我想创建一个 View 并从

开始
package eu.dzim.test

import tornadofx.View
import tornadofx.borderpane

class Root : View("My View") {
    override val root = borderpane {

    }
}

但是像 import tornadofx.View 这样的导入从未得到解决。

有没有问题,因为 Tornado 似乎使用 Kotlin 1.0.5,而我想使用 1.0.6? (虽然这没有效果,如果我改变它,关于(仍然未使用,因为"unresolved")View...)

此致, 丹尼尔

IDEA 分析构建文件并生成无效元数据时似乎出了点问题,可能是由于对构建配置的增量更改。要重新生成元数据,请执行以下操作

  • 关闭IDEA
  • 删除项目文件夹中的 .idea 文件夹
  • 导入项目

这次元数据将从已经完成的构建文件中生成,并且应该正确设置。

另请注意,Kotlin 插件默认情况下会编译 src/main/kotlin 中的 Kotlin 源代码。更改源文件夹或配置 Kotlin 插件以在 src/main/java:

中编译源代码
sourceSets {
    main.kotlin.srcDirs += 'src/main/java'
}