Getting unsupported major.minor version error when packaging tornadofx app - gradle

I've been developing a Tornadofx app for a couple months now. It runs just fine within the IDE (intellij ultimate, win 10), but now that I need to create an actual executable jar for other people to run it, I cannot seem to get it to work.
I'm using the openfx gradle plugin to automatically gather the javafx dependencies and provide the application/run task, which I've been utilizing during development. The documentation there also has you include org.beryx.jlink as a plugin for this final packaging process. This being a tornadofx app, I've written the entire thing in Kotlin. The problem I'm having now is that when I run the jlink, jlinkZip, or jpackage tasks (which I'm assuming would provide me with a distributable build), I'm receiving the error "Unsupported major.minor version 56.0."
I did some digging, thought, "maybe I need to update my jdk from 12 to 14" so I installed openjdk14 and now the error is "Unsupported major.minor version 58.0." So, clearly the problem is that my jdk is too updated...? I'm not sure. However, I don't know what version of the jdk I need to get this to build. I'm just not sure where to go from here. Some other research I've done has stated that jlink doesn't work with kotlin, but that the 'org.beryx.jlink' gradle plugin is "Badass jlink" and can work with Kotlin.
For further background, I have multiple sub-modules and a separately built internal core library, so there are a lot of pieces to build and put together. However, each submodule build.gradle looks something like this:
apply from: "$rootDir/kotlin-module.gradle"
apply from: "$rootDir/local-repositories.gradle" // helps resolve the local version of the core module.
dependencies {
implementation "<--anonymized core module-->"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3"
testImplementation 'io.cucumber:cucumber-java8:5.5.0'
testImplementation 'io.cucumber:cucumber-junit:5.5.0'
implementation project(":application")
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--add-plugin', 'html:build/cucumber/html-report', '--glue', '<-- root package name -->', 'src/test/resources/features', '--strict']
}
}
}
while the kotlin-module.gradle file looks like this:
apply plugin: 'kotlin'
group '<-- anonymized group name -->'
version '0.1.0'
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.0'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "13" // version issue here?
}
compileTestKotlin {
kotlinOptions.jvmTarget = "13" // version issue here?
}
test {
useJUnitPlatform()
}
The actual submodule that includes javafx and tornadofx looks like this:
plugins {
id 'java'
id 'application'
id 'org.jetbrains.kotlin.jvm'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.12.0'
id 'edu.sc.seis.launch4j' version '2.4.6'
id 'no.tornado.fxlauncher' version '1.0.20'
}
apply from: "$rootDir/kotlin-module.gradle"
apply from: "$rootDir/local-repositories.gradle"
repositories {
jcenter()
}
dependencies {
implementation "<--anonymized core module-->"
implementation project(":application")
implementation project(":data")
implementation project(":gui")
implementation "no.tornado:tornadofx:1.7.19"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-javafx:1.3.3"
testImplementation 'io.cucumber:cucumber-java8:5.5.0'
testImplementation 'io.cucumber:cucumber-junit:5.5.0'
implementation "de.jensd:fontawesomefx-commons:11.0"
implementation "de.jensd:fontawesomefx-controls:11.0"
implementation "de.jensd:fontawesomefx-fontawesome:4.7.0-11"
implementation "de.jensd:fontawesomefx-materialicons:2.2.0-11"
implementation "de.jensd:fontawesomefx-emojione:2.2.7-11"
}
javafx {
version = "14"
modules = [ 'javafx.controls', 'javafx.fxml'/*, 'javafx.web', 'javafx.swing'*/ ]
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = '<-- name of root module -->'
}
}
mainClassName = '<-- package.path.to.kotlin.class.extending.tornadofx.Application -->'
launch4j {
mainClassName = '<-- package.path.to.kotlin.class.extending.tornadofx.Application -->'
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--glue', '<-- root package name -->', 'src/test/resources/features', '--strict']
}
}
}
And finally, the parent build.gradle file:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.70'
}
group '<-- anonymized group name -->'
version '0.1.0'
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.0'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "13" // version issue here?
}
compileTestKotlin {
kotlinOptions.jvmTarget = "13" // version issue here?
}
test {
useJUnitPlatform()
}
I'm really hoping someone has some insight into what else I can do to get this to build. This is really confusing to me because I've been building it and running it within the IDE no problem this entire time.

Gradle 6.3 is the latest release (as of this comment) and is also the first release to support Java 14. Simply upgrade your Gradle wrapper:
./gradlew wrapper --gradle-version=6.3
https://docs.gradle.org/6.3/release-notes.html

I noticed that org.beryx.jlink plugin only works with Java 11, and with Java 14 I got this error:
Execution failed for task ':createMergedModule'.
> Unsupported major.minor version 58.0
And so to make it work I ran java 11 jlink. In my build.gradle (gradle-6.3) I used this:
jlink {
javaHome = '/usr/lib/jvm/jdk-11.0.6+10'
......
}
and specified this for jpackage to pick up the java 14 version:
jpackage {
jpackageHome = '/usr/lib/jvm/jdk-14+36'
......
}
Also used this version:
plugins {
id "org.beryx.jlink" version "2.17.4"
}
Hope this helps.

Related

Gradle dependency resolution issue

I am converting a project from Maven to Gradle.
Here is my gradle.build file
plugins {
id 'java'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "1.5.30"
id "org.jetbrains.kotlin.plugin.spring" version "1.5.30"
id 'org.springframework.boot' version "2.5.4"
id 'io.spring.dependency-management' version "1.0.11.RELEASE"
}
group = 'com.aeonai.lib'
version = '1.0.0'
description = 'Aeon AI Library'
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
maven {
url = uri 'https://repo.osgeo.org/repository/release/'
}
maven {
url = uri 'https://repo.maven.apache.org/maven2/'
}
}
dependencies {
...
implementation 'org.geotools:gt-cql:25.2:sources#jar'
implementation 'org.geotools:gt-epsg-hsql:25.2:sources#jar'
implementation 'org.geotools:gt-geojson:25.2:sources#jar'
implementation 'org.geotools:gt-main:25.2:sources#jar'
implementation 'org.geotools:gt-opengis:25.2:sources#jar'
implementation 'org.geotools:gt-shapefile:25.2:sources#jar'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
...
}
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
}
bootRun.enabled = false
bootJar {
mainClass.set('NONE')
}
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
test {
useJUnitPlatform()
}
I am importing many of the geotools from https://repo.osgeo.org/repository/release/.
When I run gradle build all of my dependency show up as they should, but the build still fails. The compiler cannot find some of the dependencies (which I have added in a screenshot below), although I can see the files in the External Libraries tree (also in a screenshot below). I can also see the libraries in the ~/.gradle/caches.
Here is a screenshot of the files not being found.
Here is another screenshot of the files in the tree.
Why is gradle/compiler not recognizing the file is there? What else am I missing?

JavaFX, How can I use "import java.util.Random;", 'Cannot resolve symbole "java".' under Gradle

I just need a random variable, but when i try to import something from java... I got this error. Im working with gradle, javafx and intelliJ.
When I try to "/gradlew build" I got the same error.
The function "System." doesnt even work. System.out.print("");
The issue could be either
that you have not started with good build.gradle
or there are some import issues with IntelliJ
Here is a simple gradle build that works with both gradle build and run.
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
sourceCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
javafx {
version = "14"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
group 'com.fx'
version '1.0-SNAPSHOT'
mainClassName = 'com.fx.HelloFX'
jar {
manifest {
attributes 'Main-Class': 'com.fx.HelloFX',
'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' ')
}
} }
}

How do I configure KoTest with Gradle in a LibGdx project? Currently can't build because StringSpec is not recognised

I have a standard LibGdx project setup by the LibGdx tool, only targeting desktop. It uses Gradle (Groovy DSL) to manage dependencies and tasks. I've converted the core module to Kotlin, and I'm trying to add a Kotlin test module using Kotest.
I've followed the Kotest instructions for Gradle on their GitHub but the compile is failing because StringSpec isn't reocgnised (Unresolved reference: StringSpec). I think LibGdx's default Gradle setup may be a little outdated or use older syntax/structure, and perhaps it's conflicting with Kotest's instructions intended for newer versions of Gradle?
For now I've removed any test and am just trying to get it to recognise StringSpec and compile. I've not even reached the stage of getting IntelliJ to recognise and run the tests. Here's what I have so far:
core.tests/tests/com/me/game/AcceptanceTests.kt
package com.jansky.myproject
class AcceptanceTests : StringSpec() {
}
core.tests/gradle.build
version '1.0'
sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "tests/" ]
tasks.withType(Test) {
useJUnitPlatform()
}
eclipse.project.name = appName + "-core.tests"
./build.gradle (ie the root buildfile)
buildscript {
ext.kotlinVersion = '1.3.71'
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
apply plugin: "eclipse"
version = '1.0'
ext {
appName = "game"
gdxVersion = '1.9.10'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "kotlin"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
}
}
project(":core") {
apply plugin: "kotlin"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
}
}
project(":core.tests") {
apply plugin: "kotlin"
test {
useJUnitPlatform()
}
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
compile "com.badlogicgames.ashley:ashley:1.7.3"
compile group: 'io.github.libktx', name: 'ktx-ashley', version: '1.9.10-b4'
implementation 'io.kotest:kotest-runner-junit5:4.0.2'
implementation 'io.kotest:kotest-assertions-core:4.0.2'
}
}
settings.gradle
include 'desktop', 'core', 'core.tests'
Gradle-wrapper.properties
#Sat Apr 04 15:53:20 BST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
I don't have much JVM experience, so I'm at a bit of a loss. Hopefully I've missed something that's obvious to someone that knows Gradle better. Any ideas?

Two versions of module javafx.base in gradle/JavaFX project

My team is working on a java project. (git repo # https://github.com/RaiderRobotix/Scouting-Client-FX). We are trying to package it using jlink. The following is displayed when running the jlink task (gradlew jlink). I'm using gradle 6.1.1, with jdk 11 on macOS. If you'd like to see our module-info.java, please check the repo. I didn't want to make this question too lengthy.
BTW, I have multiple JDK's on my machine (8,11). Building the project works, but running it with gradlew run does not (I think its an unrelated issue with lombok).
Full error: Error: Two versions of module javafx.base found in ./build/jlinkbase/jlinkjars (Infinite Recharge Client-v4.0.0-alpha.jar and javafx-base-11-mac.jar)
build.gradle
plugins {
id 'java'
id 'idea'
id "org.openjfx.javafxplugin" version "0.0.8"
id 'org.beryx.jlink' version '2.17.2'
id "com.github.johnrengelman.shadow" version "5.2.0"
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'com.github.gmazzo.buildconfig' version '1.6.2'
}
group = "com.github.RaiderRobotix"
version = "v4.0.0-alpha"
repositories {
maven { url 'https://jitpack.io' }
jcenter()
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
jar {
manifest {
attributes (
'Implementation-Title': 'Raider Robotix Scouting Client',
'Implementation-Version': project.version,
'Main-Class': 'org.usfirst.frc.team25.scouting.client.ui.Main'
)
}
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
}
dependencies {
implementation 'com.github.RaiderRobotix:Scouting-Models:29617b7dcc'
implementation 'com.github.RaiderRobotix:blue-alliance-api-java-library:3.0.0'
implementation 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
implementation 'com.google.code.gson:gson:2.+'
implementation 'commons-io:commons-io:2.+'
implementation 'org.apache.commons:commons-math3:3.+'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
}
buildConfig {
packageName "com.raiderrobotix"
buildConfigField 'String', 'TBA_API_KEY', project['TBA_API_KEY']
// The escaped quotes here are NEEDED. The plugin copies the TEXT LITERAL given to it. The quotes are part of this.
buildConfigField 'String', 'VERSION', "\"$version\""
}
javafx {
version = "11"
modules = [
'javafx.base',
'javafx.graphics',
'javafx.controls',
'javafx.fxml',
]
}
jlink {
launcher {
name = 'Scouting Client'
}
}
application {
mainClassName = 'org.raiderrobotix.scouting.client/org.raiderrobotix.scouting.client.ui.Main'
}
wrapper {
gradleVersion = '6.1.1'
}
compileKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
I had a similar issue, my specific error during jlink was:
Error: Two versions of module javafx.base found in C:\Users\tareh\code\cleopetra\build\jlinkbase\jlinkjars (javafx-base-11.0.2-win.jar and javafx-base-11.0.2-linux.jar)
Execution failed for task ':jlink'.
I got some inspiration from https://github.com/openjfx/javafx-gradle-plugin/issues/65 and changed one of my dependencies in build.gradle:
dependencies {
// Get rid of this
// compile group: 'org.controlsfx', name: 'controlsfx', version: '11.0.3'
// Use this instead
implementation('org.controlsfx:controlsfx:11.0.3') {
exclude group: 'org.openjfx'
}
}
After I did that, the jlink error went away, and also I noticed the linux jars which had been listed in my IntelliJ module dependencies had disappeared (I'm on Windows).
This doesn't address your specific problem, but hopefully this will be helpful to others.
In my case I had to comment jar block in build.gradle to perform jlink command. I guess that problem is related to how plugin 'org.beryx.jlink' resolves modules when jar block is appear.

Gradle Kotlin Native - You have not specified any compilation arguments. No output has been produced

I'm pretty new to Gradle and Kotlin Native. I want to setup my build.gradle so that I can use Native to compile my code. I'm using the Konan plugin to do this. It worked fine when I hard-coded my class in the konanArtifacts.program.srcFiles. But obviously if I add more classes, I'll have to add the paths to srcFiles and I don't (and shouldn't) need to. So I looked around to find a way to add any classes I add automatically, and I attempted sourceSets. But when I try to run the compileKonanClientMingw task now my gradle console gives me the following:
error: you have not specified any compilation arguments. No output has been produced.
I'm not entirely sure that I'm using sourceSets correctly, but this seems to be the farthest I got. Below is my build.gradle
build.gradle:
buildscript {
ext.kotlin_version = '1.2.41'
ext.konan_version = '0.6'
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$konan_version"
}
}
plugins {
id 'java'
}
group 'net.dev909'
version '1.0'
apply plugin: 'kotlin'
apply plugin: 'konan'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
sourceSets.main.allSource.srcDir '/src/main/kotlin/'
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
konanArtifacts {
program('client-' + version) {
srcFiles sourceSets.main.runtimeClasspath
}
}
Source sets are a part of the Java world and the Java plugin, so the Kotlin/Native plugin avoids using them to be independent on Java. But you still able to compile a bunch of classes, just specify the srcDir parameter:
konanArtifacts {
program('client-' + version) {
srcDir 'src/main/kotlin/'
}
}
Also note that src/main/kotlin/ is a default source path. So if you use only this path, you don't need to specify it explicitly. You may just write:
konanArtifacts {
program('client-' + version)
}

Resources