You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用nu.studer.jooq Gradle插件时SLF4J StaticLoggerBinder缺失问题

解决nu.studer.jooq Gradle插件生成代码时SLF4J日志实现缺失问题

nu.studer.jooq插件的jooqGenerator任务拥有独立的类路径,默认不会自动继承项目根依赖中的SLF4J实现。而mariadb-java-client自带SLF4J API依赖,这就导致生成代码时类路径里只有API没有具体实现,触发SLF4J找不到org.slf4j.impl.StaticLoggerBinder的警告。以下是两种可行的解决方式:

方式一:给jooqGenerator任务添加SLF4J实现依赖

直接为jooqGenerator任务的专属类路径添加SLF4J实现包,这是最常用的解决方案:

Groovy DSL(build.gradle)

jooq {
    configurations {
        generator {
            dependencies {
                // 根据你使用的日志框架选择对应的实现包,示例为Log4j 1.x适配
                implementation 'org.slf4j:slf4j-log4j12:1.7.36'
                // 如果用Log4j 2,替换为:
                // implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.20.0'
                // 同时需要添加Log4j核心依赖:
                // implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
            }
        }
    }

    // 你的jOOQ生成配置(比如database、generator等)
    // ...
}

Kotlin DSL(build.gradle.kts)

jooq {
    configurations {
        generator {
            dependencies {
                implementation("org.slf4j:slf4j-log4j12:1.7.36")
                // Log4j 2版本替换为:
                // implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.20.0")
                // implementation("org.apache.logging.log4j:log4j-core:2.20.0")
            }
        }
    }

    // 你的jOOQ生成配置
    // ...
}

方式二:为插件自身类路径添加SLF4J实现

如果警告出现在插件初始化阶段(而非generator任务执行时),需要将SLF4J实现加入插件的类路径,修改settings.gradle(或settings.gradle.kts):

Groovy DSL(settings.gradle)

pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }
    dependencies {
        classpath 'org.slf4j:slf4j-log4j12:1.7.36'
        classpath 'nu.studer:jooq-plugin:8.2.1'
    }
}

Kotlin DSL(settings.gradle.kts)

pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }
    dependencies {
        classpath("org.slf4j:slf4j-log4j12:1.7.36")
        classpath("nu.studer:jooq-plugin:8.2.1")
    }
}

注意事项

  • 确保SLF4J实现的版本与mariadb-java-client依赖的SLF4J API版本兼容:比如如果驱动依赖SLF4J 1.7.x,就不要使用SLF4J 2.x的实现包,避免版本冲突。
  • 若使用Log4j 2,必须同时包含log4j-slf4j-impl和log4j-core依赖,否则日志功能无法正常工作。

内容的提问来源于stack exchange,提问作者Stefano Bossi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 08:36:57