gpt4 book ai didi

gradle - Kotlin 1.3+打破SLF4J/log4j

转载 作者:行者123 更新时间:2023-12-02 13:08:46 25 4
gpt4 key购买 nike

我正在尝试将项目升级到Kotlin 1.3,但是由于我们使用HikariCP以及许多其他使用SLF4J / log4j的库而遇到麻烦,并且由于Kotlin 1.3及更高版本,它们全部由于某种原因而损坏。

仅通过更改Kotlin版本就会出现此问题。为什么更改Kotlin会影响SLF4J / log4j行为?

java.lang.NoSuchMethodError: org.apache.log4j.Level.isGreaterOrEqual(Lorg/apache/log4j/Priority;)Z
at org.apache.log4j.Category.isDebugEnabled(Category.java:736)
at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:251)
at com.zaxxer.hikari.HikariConfig.attemptFromContextLoader(HikariConfig.java:901)
at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:474)
at ps.eden.server.game.system.mysql.SQLManager.init(SQLManager.java:86)

这是我们使用的gradle build配置,我们唯一的区别是版本是 1.2.71而不是 1.3.11:
buildscript {
ext.kotlin_version = '1.3.11'

repositories {
jcenter()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2'
}
}

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'application'

mainClassName = "ps.eden.server.Eden"

group 'ps.eden'
version '1.4.0'

targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8

eclipse {
classpath {
containers 'org.jetbrains.kotlin.core.KOTLIN_CONTAINER'
}
}

compileKotlin {
kotlinOptions.suppressWarnings = true
}

sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
main.java.srcDirs += 'src/main/java'
}

repositories {
jcenter()
flatDir { dirs 'lib' }
maven { url 'https://jitpack.io' }
maven { url "https://dl.bintray.com/kotlin/kotlinx/" }
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile group: 'org.jetbrains.kotlin', name: 'kotlin-scripting-common', version: "$kotlin_version"
compile group: 'org.jetbrains.kotlin', name: 'kotlin-scripting-jvm', version: "$kotlin_version"
compile group: 'org.jetbrains.kotlin', name: 'kotlin-scripting-jvm-host', version: "$kotlin_version"

compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.47'
compile group: 'joda-time', name: 'joda-time', version: '2.10.1'
compile(group: 'com.zaxxer', name: 'HikariCP', version: '3.3.0') {
exclude module: 'slf4j-api'
}
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.5'
compile group: 'org.apache.commons', name: 'commons-compress', version: '1.18'
compile(group: 'org.apache.hadoop', name: 'hadoop-common', version: '3.1.1') {
exclude module: 'slf4j-api'
exclude module: 'slf4j-log4j'
exclude module: 'slf4j-log412j'
}
compile group: 'org.apache.ant', name: 'ant', version: '1.10.5'
compile group: 'it.unimi.dsi', name: 'fastutil', version: '8.2.2'
compile group: 'io.netty', name: 'netty-all', version: '4.1.32.Final'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'org.reflections', name: 'reflections', version: '0.9.11'
compile group: 'com.github.salomonbrys.kotson', name: 'kotson', version: '2.5.0'
compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
compile 'com.github.rockaport:alice:0.9.0'
compile group: 'at.favre.lib', name: 'bcrypt', version: '0.6.0'
compile group: 'net.openhft', name: 'zero-allocation-hashing', version: '0.8'
compile('net.dv8tion:JDA:3.8.1_437') {
exclude module: 'opus-java'
}
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
}

compileJava {
options.encoding = "UTF-8"

//enable compilation in a separate daemon process
options.fork = true

//enable incremental compilation
options.incremental = true
}

最佳答案

您正在使用kotlin脚本库,特别是kotlin-scripting-jvm-host,它拉出了kotlin编译器jar。您可以尝试使用kotlin-scripting-jvm-host-embeddable代替:它取决于编译器jar的“可嵌入”版本,其中 bundle 的3rd Party类被“阴影化”。

编辑:从Kotlin版本1.3.20开始,可以使用kotlin-scripting-jvm-host-embeddable(在撰写本文时-仅以预发行形式)。

关于gradle - Kotlin 1.3+打破SLF4J/log4j,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54160082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com