我正试图将一个项目升级到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)
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
}