I'm packaging a shadow jar of my app. The app uses kotlin and some external dependencies. All dependencies are in my jar but i get the following exception during runtime:
java.lang.NoSuchMethodError: java.util.Optional.isEmpty()Z
The Z at the end is always there; I don't where it comes from.
I checked multiple example of build.gradle files and mine seems to be good.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
group 'com.bancarelvalentin'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'kotlin'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "com.discord4j:discord4j-core:3.1.0"
implementation "com.natpryce:konfig:1.6.10.0"
implementation "org.json:json:20200518"
implementation "ch.qos.logback:logback-classic:1.2.3"
implementation "org.slf4j:slf4j-api:1.7.30"
}
shadowJar {
archiveBaseName.set('DreamBot')
archiveClassifier.set('')
archiveVersion.set('0.0.0')
mergeServiceFiles()
manifest {
attributes 'Main-Class': 'com.bancarelvalentin.dreambot.Main'
}
}
I have trouble identifying the exact problem is it my java install that is not working properly or is it my jar missing stuff ?
Thanks for your help !
Your runtime Java Version is lower than the compile-time Java version
Optional.isEmpty() is from JDK 11+, its not in JDK 8,9
the build.gradle is fine.
just run with JDK 11