java.lang.ClassNotFoundException:运行org.jooq.jooq-codegen-gradle时出现org.mariadb.jdbc.Driver

问题描述 投票:0回答:1

我目前正在尝试从

nu.studer.jooq
迁移到新的官方 gradle 插件。 我正在使用 jOOQ 3.19.0,这是我当前的 build.gradle:

plugins {
    id 'java'
    id 'org.jooq.jooq-codegen-gradle' version "3.19.0"
    id 'org.springframework.boot' version '3.0.5'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'org.springdoc.openapi-gradle-plugin' version "1.6.0"
}

group = 'redacted'
version = '1'
java.sourceCompatibility = JavaVersion.VERSION_18

def lombokVersion = "1.18.30"
def jooqVersion = "3.19.0"
def mariaDbVersion = "3.3.1"
def flywayVersion = "9.4.0"
def springdocOpenApiVersion = "2.2.0";
def temporalVersion = "1.22.3"

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

openApi {
    apiDocsUrl.set("http://localhost:2001/api-docs")
    waitTimeInSeconds.set(20)
    outputDir.set(file("../../openapi/"))
    outputFileName.set("OpenApi.json")
}

repositories {
    maven {
        // using a private maven repo which passes through to maven central
    }
}

dependencies {
    // Spring
    implementation "org.springframework.boot:spring-boot-configuration-processor"

    // Database
    implementation "org.springframework.boot:spring-boot-starter-data-jdbc"
    implementation "org.flywaydb:flyway-core:$flywayVersion"
    implementation "org.flywaydb:flyway-mysql:$flywayVersion"
    implementation "org.jooq:jooq:$jooqVersion"
    implementation "org.jooq:jooq-meta:$jooqVersion"
    implementation "org.jooq:jooq-codegen:$jooqVersion"
    implementation "org.mariadb.jdbc:mariadb-java-client:$mariaDbVersion"

    // Lombok
    compileOnly "org.projectlombok:lombok:$lombokVersion"
    annotationProcessor "org.projectlombok:lombok:$lombokVersion"
    testCompileOnly "org.projectlombok:lombok:$lombokVersion"
    testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"

    // web
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation "org.springframework.boot:spring-boot-starter-validation"

    // openapi
    implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:$springdocOpenApiVersion"

    // Min.io
    implementation "io.minio:minio:8.4.6"

    // Temporal
    implementation "io.temporal:temporal-sdk:$temporalVersion"
    implementation 'com.google.protobuf:protobuf-java-util:3.25.0'

    // Micrometer
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework:spring-aspects'
    implementation 'org.springframework.boot:spring-boot-starter-aop'
    implementation 'io.micrometer:micrometer-registry-prometheus:1.9.7'

    // json
    implementation 'org.json:json:20230618'

    // tests
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation "io.temporal:temporal-testing:$temporalVersion"
}

tasks.named('test') {
    useJUnitPlatform()
}

java {
    withSourcesJar()
}

jooq {
    configuration {
        jdbc {
            driver = 'org.mariadb.jdbc.Driver'
            url = 'jdbc:mariadb://localhost:3306'
            user = 'root'
            password = 'password'
            schema = 'redacted'
        }
        logging = org.jooq.meta.jaxb.Logging.TRACE
        generator {
            name = 'org.jooq.codegen.DefaultGenerator'
            database {
                name = 'org.jooq.meta.mariadb.MariaDBDatabase'
                inputSchema = 'redacted'
                excludes = "flyway_schema_history"
                forcedTypes {
                    // forced types
                }
            }
            generate {
                deprecated = false
                records = true
                immutablePojos = false
                fluentSetters = false
            }
            target {
                packageName = 'redacted'
                directory = 'src/generated/java'
            }
            strategy {
                name = "org.jooq.codegen.DefaultGeneratorStrategy"
            }
        }
    }
}

我遇到的问题是

jooqCodegen
任务抛出
java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver
。全栈:

> Task :jooqCodegen FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jooqCodegen'.
> java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
1 actionable task: 1 executed

MariaDB 驱动程序类存在于应用程序 jar 中,如果我将插件回滚到

nu.studer
,则可以正常工作。 我错过了什么还是有错误?

我尝试将驱动程序更改为 Postgres,但出现了相同的错误。

jooq
1个回答
0
投票

更新:

在 jOOQ 的 GitHub 上创建了一个 issue 并得到了正确答案:

dependencies {
    jooqCodegen "org.mariadb.jdbc:mariadb-java-client:$mariaDbVersion"
}

发现我需要在build.gradle的开头添加buildscript:

buildscript {
    repositories {
        maven {
           // private repo
        }
    }
    dependencies {
        classpath  "org.mariadb.jdbc:mariadb-java-client:3.3.1"
    }
}
// rest of build.gradle
© www.soinside.com 2019 - 2024. All rights reserved.