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

1.6k views Asked by At

I currently try to combine the following technologies:

  • Gluon (Mobile)
  • Gradle (dependency of Gluon, since they rely on it)
  • Kotlin (because it's a nice language I want to dive into)
  • Tornado FX (I guess it's for JavaFX, what Anko is for Android)

The issue is, that I'm relatively new to Intellij-IDEA and have issues setting it up properly, although I though, that the build.gradle file was appropriate enough.

Here's what my build.gradle looks so far:

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'
    }
}

I at lease managed to stop the IDE to complain about Kotlin. I converted a simple application class to look like this:

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()
    }
}

But now I'm stuck, because the dependency to Tornado FX is not resolved properly. I wanted to create a View and started with

package eu.dzim.test

import tornadofx.View
import tornadofx.borderpane

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

    }
}

But the imports like import tornadofx.View never get resolved.

Is there an issue, because Tornado seems to use Kotlin 1.0.5, while I want to use 1.0.6? (Although this has no effect, if I change it, regarding the (still unused, because "unresolved") View...)

Regards, Daniel

1

There are 1 answers

0
Edvin Syse On BEST ANSWER

It looks like something went wrong when IDEA analyzed the build file and generated invalid metadata, probably due to incremental changes to your build config. To regenerate the metadata, do the following

  • Close IDEA
  • Remove the .idea folder inside the project folder
  • Import the project

This time the metadata would be generated from the already complete build file and it should be set up correctly.

Also note that the Kotlin plugin by default will compile Kotlin sources in src/main/kotlin. Either change the source folder or konfigure the Kotlin plugin to compile sources in src/main/java:

sourceSets {
    main.kotlin.srcDirs += 'src/main/java'
}