簡體   English   中英

JOOQ 不生成

[英]JOOQ Doesn't Generate

我跟着這里 我使用postgresql而不是h2 我能夠用一些額外的字段來構建項目。

我在 com.example.demo 下創建了一個com.example.demo database ,但是在項目構建后它仍然是空的。

build.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 package 中看不到 pojos 和 daos? 我的數據庫只有一張有 2 列的表。

當我輸入./gradlew generateBUILD SUCCESSFULL ,但沒有生成任何內容。

你的文件看起來不錯。 我有一個類似的問題(在使用 Maven 時)。 嘗試三件事(對我有用):

  1. 檢查“withInputSchema”屬性中模式的大小寫。 嘗試傳遞大寫的 PUBLIC。
  2. 嘗試將 'src/main/java' 更改為 './src/main/java'
  3. 添加“包含”並在其中傳遞。*(為架構中的所有表生成)

您可以嘗試./gradlew generate --info命令,該命令將為您提供有關構建過程的更多信息。

我的 gradle 腳本與您的非常相似。 通過使用上面的命令,我發現這些類實際上是生成的,但是在不同的文件夾/Users/{MyUserName}/.gradle/daemon/7.1.1/src/main/java中。

所以我必須用def outputDirectory = projectDir.toString() + '/src/main/java'明確設置 output 目錄。

這對我有用


buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        classpath 'org.jooq:jooq-codegen:3.16.2'
        classpath 'mysql:mysql-connector-java:8.0.27'
    }
}

plugins {
    id 'org.springframework.boot' version '2.6.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

if(JavaVersion.current() != JavaVersion.VERSION_11){
    throw new GradleException("This build must be run with java 11")
}

repositories {
    mavenCentral()
}

group = 'snorlax'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

//create a fat Jar with all dependencies
jar {
    duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
    from {
        configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
    manifest {
        attributes "Main-Class": "com.snorlax.userservice.MainApplication"
    }
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

dependencies {
    // Spring boot
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    // Swagger
    implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
    implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'

    // Lombok
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'

    // RDS Connection
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'mysql:mysql-connector-java:8.0.27'

    // AWS secretes manager
    implementation 'com.amazonaws.secretsmanager:aws-secretsmanager-jdbc:1.0.6'

    // JOOQ
    implementation 'org.springframework.boot:spring-boot-starter-jooq'
    implementation 'org.jooq:jooq-meta:3.16.2'
    compileOnly 'org.jooq:jooq-codegen:3.16.2'

}

test {
    useJUnitPlatform()
}

/************************
    jooq code generation
 *************************/
import org.jooq.codegen.GenerationTool;
import org.jooq.meta.jaxb.*;

task generate {
    def outputDirectory = projectDir.toString() + '/src/main/java'
    def configuration = new Configuration()
            .withJdbc(new Jdbc()
            .withDriver('com.mysql.cj.jdbc.Driver')
            .withUrl('jdbc:mysql://127.0.0.1:3306/snorlaxRds')
            .withUser('root')
            .withPassword('123456'))
            .withGenerator(new Generator()
                    .withDatabase(new Database().withInputSchema("snorlaxRds"))
                    .withGenerate(new Generate()
                            .withPojos(true)
                            .withDaos(true))
                    .withTarget(new Target()
                            .withPackageName('snorlax.userservice.database')
                            .withDirectory(outputDirectory)));

    doLast {
        GenerationTool.generate(configuration)
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM