gpt4 book ai didi

gradle - gradle 项目中最新 JOOQ 库的 JOOQ 插件

转载 作者:行者123 更新时间:2023-12-04 14:12:46 29 4
gpt4 key购买 nike

我在我的 java gradle 项目中找到一个有效的 JOOQ 插件或其配置为最新的 JOOQ 库时遇到问题。

我找到了以下插件:

  • https://github.com/jOOQ/jOOQ/tree/master/jOOQ-examples/jOOQ-codegen-gradle

  • 由于错误消息,这对我不起作用:
    Could not find any version that matches org.jooq:jooq-codegen-gradle:latest.integration.
    Searched in the following locations:
    http://repo1.maven.org/maven2/org/jooq/jooq-codegen-gradle/maven-metadata.xml
    http://repo1.maven.org/maven2/org/jooq/jooq-codegen-gradle/
  • https://github.com/ben-manes/gradle-jooq-plugin

  • 这仅适用于 JOOQ 3.2.2(最新的 3.4.2 不起作用)。如果我将其设置为 3.4.2,则 jooqGenerate 执行成功但数据获取调用错误消息:
    Error:(12, 8) java: org.jooq.generated.tables.records.PersonsRecord is not abstract and does not override abstract method values(java.lang.Integer,java.lang.String,java.lang.String) in org.jooq.Record3

    我做错了什么?

    那是我的 gradle.build:
    apply plugin: 'java'
    apply plugin: 'jooq'

    sourceCompatibility = 1.5
    version = '1.0'

    repositories {
    jcenter()
    }

    dependencies {
    compile 'org.jooq:jooq:3.4.2'
    compile 'org.jooq:jooq-meta:3.4.2'
    compile 'org.jooq:jooq-codegen:3.4.2'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    }

    buildscript {
    repositories {
    jcenter()
    }

    dependencies {
    classpath 'com.github.ben-manes:gradle-jooq-plugin:+'
    classpath 'mysql:mysql-connector-java:+'
    }
    }

    jooq {
    jdbc {
    url 'jdbc:mysql://localhost:3306'
    driver 'com.mysql.jdbc.Driver'
    user 'admin'
    passwoed 'xxx'
    }
    generator {
    database {
    name 'org.jooq.util.mysql.MySQLDatabase'
    inputSchema 'test_db'
    includes '.*'
    }
    }
    }

    我在其中获取数据的 App.class:
    import static org.jooq.generated.Tables.PERSONS;

    public class App {

    public static void main(String[] args) {
    try(Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db","admin","xxx")){
    DSLContext create = DSL.using(c, SQLDialect.MYSQL);

    for(PersonsRecord personsRecord : create.selectFrom(PERSONS).fetch()) {
    System.out.println(personsRecord
    );
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

    编辑:

    更新了 https://github.com/etiennestuder/gradle-jooq-plugin 的 build.gradle 文件:
    apply plugin: 'nu.studer.jooq'

    buildscript {
    repositories {
    jcenter()
    }

    dependencies {
    classpath 'nu.studer:gradle-jooq-plugin:+'
    classpath 'mysql:mysql-connector-java:+'
    }
    }

    repositories {
    jcenter()
    }

    dependencies {
    compile 'org.jooq:jooq:+'
    compile 'org.jooq:jooq-meta:+'
    compile 'org.jooq:jooq-codegen:+'
    compile 'mysql:mysql-connector-java:+'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    }

    jooq {
    jdbc {
    url 'jdbc:mysql://localhost:3306'
    driver 'com.mysql.jdbc.Driver'
    user 'admin'
    password 'xxx'
    }
    generator {
    database {
    name 'org.jooq.util.mysql.MySQLDatabase'
    inputSchema 'test_db'
    includes '.*'
    }
    generate {
    daos true
    classes false
    }
    }
    }

    工作 gradle 脚本:
    apply plugin: 'nu.studer.jooq'

    buildscript {
    repositories {
    jcenter()
    }
    dependencies {
    classpath 'nu.studer:gradle-jooq-plugin:1.0.5'
    classpath 'mysql:mysql-connector-java:+'
    }
    }

    repositories {
    jcenter()
    }

    dependencies {
    compile 'org.jooq:jooq:+'
    compile 'mysql:mysql-connector-java:+'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    }


    jooq {
    sample(sourceSets.main) {
    jdbc {
    driver = 'com.mysql.jdbc.Driver'
    url = 'jdbc:mysql://localhost:3306/test_db'
    user = 'admin'
    password = 'qwerty123'
    schema = 'test_db'
    }
    generator {
    name = 'org.jooq.util.DefaultGenerator'
    strategy {
    name = 'org.jooq.util.DefaultGeneratorStrategy'
    }
    database {
    name = 'org.jooq.util.mysql.MySQLDatabase'
    inputSchema = 'test_db'
    }
    generate {
    daos = true
    }
    target {
    packageName = 'org.homemade.warehouse.db'
    directory = 'src/main/java'
    }
    }
    }
    }

    感谢 Lukas Eder 和 Etienne Studer,插件现在真的可以工作了!

    最佳答案

    在您为 Gradle 插件“nu.studer.jooq”提供的 build.gradle 文件中,您必须使用等号来分配配置值:

    代替:

    jdbc {
    url 'jdbc:mysql://localhost:3306'
    ....
    }

    它应该是:
    jdbc {
    url = 'jdbc:mysql://localhost:3306'
    ....
    }

    如果您使用最新版本的插件 (1.0.5),则必须为您的配置命名(因为您可以定义多个配置)并定义将生成的源添加到哪个源集:
    jooq {
    sample(sourceSets.main) {
    jdbc {
    ...
    }
    }
    }

    另见 https://github.com/etiennestuder/gradle-jooq-plugin#configuration

    如果你想强制插件使用特定版本的 jOOQ,你可以这样做:
    buildscript {
    ...

    configurations.classpath {
    resolutionStrategy {
    forcedModules = [
    'org.jooq:jooq:3.4.1',
    'org.jooq:jooq-meta:3.4.1',
    'org.jooq:jooq-codegen:3.4.1'
    ]
    }
    }
    }

    另见 https://github.com/etiennestuder/gradle-jooq-plugin#custom-jooq-version

    关于gradle - gradle 项目中最新 JOOQ 库的 JOOQ 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25339115/

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