首页 > 解决方案 > JOOQ 不生成

问题描述

我跟着这里。我用postgresql而不是h2. 我能够用一些额外的字段来构建项目。

database我在下创建了一个包com.example.demo,但是在项目构建后它仍然是空的。

构建.gradle:

buildscript {
    ext {
        springBootVersion = '2.4.2'
    }
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.jooq:jooq-codegen:3.14.4'
        classpath 'org.postgresql:postgresql:42.2.18'
    }
}


apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '15'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-jooq'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.flywaydb:flyway-core'
    runtimeOnly 'org.postgresql:postgresql'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

import org.jooq.codegen.GenerationTool
import org.jooq.meta.jaxb.*

task generate {
    def configuration = new Configuration()
    configuration
            .withJdbc(new Jdbc()
                    .withDriver('org.postgresql.Driver')
                    .withUrl('jdbc:postgresql://localhost:5432/vertx')
                    .withUser('postgres')
                    .withPassword('postgres'))
            .withGenerator(new Generator()
                    .withDatabase(new Database().withInputSchema('public'))
                    .withGenerate(new Generate()
                            .withPojos(true)
                            .withDaos(true))
                    .withTarget(new Target()
                            .withPackageName('com.example.demo.database')
                            .withDirectory('src/main/java')))

    doLast {
        GenerationTool.generate(configuration)
    }
}

有什么我想念的吗?为什么我在database包中看不到 pojos 和 daos?我的数据库只有一张有 2 列的表。

BUILD SUCCESSFULL当我键入时./gradlew generate,但没有生成任何内容。

标签: javaspringpostgresqlspring-bootjooq

解决方案


你的文件看起来不错。我有一个类似的问题(在使用 Maven 时)。尝试三件事(对我有用):

  1. 检查“withInputSchema”属性中模式的大小写。尝试传递大写的PUBLIC。
  2. 尝试将 'src/main/java' 更改为 './src/main/java'
  3. 添加“包含”并在其中传递 .* (为架构中的所有表生成)

推荐阅读