Gradle 编译在 Linux 上找不到 tornadofx

Gradle Compilation can't find tornadofx on Linux

我正在尝试使用 gradle 编译一个 kotlin 应用程序。该应用程序使用 tornadofx(kotlin 版本的 javafx)。

build.gradle中,我有:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile 'no.tornado:tornadofx:1.7.8'
    compile 'com.squareup.moshi:moshi:1.5.0'
    compile 'com.squareup.moshi:moshi-kotlin:1.5.0'

    // Required for local unit tests (JUnit 4 framework)
    testCompile 'junit:junit:4.12'
}

MyApp.kt 我有:

import javafx.application.Application
import tornadofx.App

当我在 Windows 10 上编译这个项目时,无论是使用 gradle clean build 还是 .\gradlew clean build,它都能完美地编译和运行。

当我在 Ubuntu Linux 上编译此项目时,我收到一页错误消息,包括:

...

e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class tornadofx.UIComponent, unresolved supertypes: javafx.event.EventTarget
    class tornadofx.App, unresolved supertypes: javafx.application.Application

...

e: /home/al/project/app/src/pcUi/MyApp.kt: (3, 8): Unresolved reference: javafx
e: /home/al/project/app/src/pcUi/MyApp.kt: (12, 5): Unresolved reference: Application

...

虽然如果我从干净的设置中执行此操作,gradle 输出还包括:

Download https://jcenter.bintray.com/no/tornado/tornadofx/1.7.8/tornadofx-1.7.8.pom
Download https://jcenter.bintray.com/com/squareup/moshi/moshi/1.5.0/moshi-1.5.0.pom
Download https://jcenter.bintray.com/com/squareup/moshi/moshi-parent/1.5.0/moshi-parent-1.5.0.pom
Download https://jcenter.bintray.com/com/squareup/moshi/moshi-kotlin/1.5.0/moshi-kotlin-1.5.0.pom
Download https://jcenter.bintray.com/org/glassfish/javax.json/1.0.4/javax.json-1.0.4.pom
Download https://jcenter.bintray.com/org/glassfish/json/1.0.4/json-1.0.4.pom
Download https://jcenter.bintray.com/net/java/jvnet-parent/3/jvnet-parent-3.pom
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jre8/1.1.3/kotlin-stdlib-jre8-1.1.3.pom
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.1.3/kotlin-reflect-1.1.3.pom
Download https://jcenter.bintray.com/com/squareup/okio/okio/1.13.0/okio-1.13.0.pom
Download https://jcenter.bintray.com/com/squareup/okio/okio-parent/1.13.0/okio-parent-1.13.0.pom
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jre7/1.1.3/kotlin-stdlib-jre7-1.1.3.pom
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.1.3/kotlin-stdlib-1.1.3.pom
Download https://jcenter.bintray.com/no/tornado/tornadofx/1.7.8/tornadofx-1.7.8.jar
Download https://jcenter.bintray.com/com/squareup/moshi/moshi/1.5.0/moshi-1.5.0.jar
Download https://jcenter.bintray.com/com/squareup/moshi/moshi-kotlin/1.5.0/moshi-kotlin-1.5.0.jar
Download https://jcenter.bintray.com/org/glassfish/javax.json/1.0.4/javax.json-1.0.4.jar
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jre8/1.1.3/kotlin-stdlib-jre8-1.1.3.jar
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.1.3/kotlin-reflect-1.1.3.jar
Download https://jcenter.bintray.com/com/squareup/okio/okio/1.13.0/okio-1.13.0.jar
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jre7/1.1.3/kotlin-stdlib-jre7-1.1.3.jar
Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.1.3/kotlin-stdlib-1.1.3.jar

这对我来说没有意义,因为它正在正确下载依赖项(在 Linux 和 Windows 上),但随后只能在 Windows 上成功编译,而不是 Linux。我一直无法弄清楚发生了什么,所以任何人都可以提供有关在哪里查看的任何建议吗?

查看错误信息:

e: /home/al/project/app/src/pcUi/MyApp.kt: (3, 8): Unresolved reference: javafx e: /home/al/project/app/src/pcUi/MyApp.kt: (12, 5): Unresolved reference: Application

您似乎没有在 Ubuntu 上正确设置 JDK。 JavaFX 不再是 OpenJDK 的一部分,您必须手动安装它:https://packages.qa.debian.org/o/openjfx.html .

编辑:参见 。您可能在 Windows 上使用 Oracle JDK,其中包含 JavaFX。

为了在我的项目中快速重新包含 JavaFX,我修改了 build.grade 文件并让它同步。

plugins {
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

repositories {
    mavenCentral()
}

javafx {
    version = "15.0.1"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}