简体   繁体   English

Shadow jar 缺少常见的 Java 类

[英]Shadow jar missing common java classes

I'm packaging a shadow jar of my app.我正在打包我的应用程序的影子罐。 The app uses kotlin and some external dependencies.该应用程序使用 kotlin 和一些外部依赖项。 All dependencies are in my jar but i get the following exception during runtime:所有依赖项都在我的 jar 中,但在运行时出现以下异常:

java.lang.NoSuchMethodError: java.util.Optional.isEmpty()Z java.lang.NoSuchMethodError: java.util.Optional.isEmpty()Z

The Z at the end is always there;末尾的 Z 始终存在; I don't where it comes from.我不知道它来自哪里。

I checked multiple example of build.gradle files and mine seems to be good.我检查了 build.gradle 文件的多个示例,我的似乎很好。

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 ?我无法确定确切的问题是我的 java 安装工作不正常还是我的 jar 丢失了东西?

Thanks for your help !谢谢你的帮助 !

Your runtime Java Version is lower than the compile-time Java version您的运行时 Java 版本低于编译时 Java 版本

Optional.isEmpty() is from JDK 11+, its not in JDK 8,9 Optional.isEmpty() 来自 JDK 11+,它不在 JDK 8,9 中

the build.gradle is fine. build.gradle 很好。

just run with JDK 11只需使用 JDK 11 运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM