我想为JavaFX11创建一个gradle项目。
我已经可以使用构建路径和VM参数创建并运行Java FX11项目。这只是一个解决方法,因为由于运行时版本错误,Gradle无法编译JavaFX:
java.lang.UnsupportedClassVersionError: org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Eclipse版本:2019-03
版本版本:5.2.1
操作系统:
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
我已经修复了所有可能导致问题的原因: Eclipse设置:
编译器兼容级别-> 11 已安装的JRE:jdk-11.0.2
Ubuntu Java设置:
java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
等级:
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9-LTS)
OS: Linux 4.15.0-47-generic amd64
这是我的build.gradle:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
def currentOS = org.gradle.internal.os.OperatingSystem.current()
def platform
if (currentOS.isWindows()) {
platform = 'win'
} else if (currentOS.isLinux()) {
platform = 'linux'
} else if (currentOS.isMacOsX()) {
platform = 'mac'
}
dependencies {
implementation 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.12'
}
repositories {
jcenter()
mavenCentral()
}
javafx {
moduless = ['javafx.controls','javafx.fxml']
version ='11.0.2'
}
mainClassName = 'de.dom.main.MainApp'
编辑渐变包装
gradle.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
org.gradle.java.home=/usr/lib/jvm/jdk-11.0.2
编辑程序修复
在项目的根目录中创建 包含以下内容的gradle.properties:
org.gradle.java.home=/usr/lib/jvm/jdk-11.0.2