【问题标题】:JOOQ Doesn't GenerateJOOQ 不生成
【发布时间】:2021-04-28 11:01:00
【问题描述】:

我在关注here。我使用postgresql 而不是h2。我能够使用一些额外的字段来构建项目。

我在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 包中看不到 pojos 和 daos?我的数据库只有一个有 2 列的表。

当我输入./gradlew generateBUILD SUCCESSFULL,但没有生成任何内容。

【问题讨论】:

  • @LukasEder,感谢您的参与。输出仅显示build success。我假设一旦我输入./gradlew clean build,它就会被调用。我想我要么在教程之间迷路了,要么错过了一些东西。
  • 嘿,您找到解决方案了吗?我有完全相同的问题。 @Eniss

标签: java spring postgresql spring-boot jooq


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您可以尝试./gradlew generate --info 命令,它将为您提供有关构建过程的更多信息。

    我的 gradle 脚本和你的很相似。通过使用上面的命令,我发现类实际上是生成的,但是在不同的文件夹/Users/{MyUserName}/.gradle/daemon/7.1.1/src/main/java

    所以我必须用def outputDirectory = projectDir.toString() + '/src/main/java' 显式设置输出目录。

    这对我有用

    
    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)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-31
      • 2021-12-29
      • 2021-01-27
      • 2020-09-03
      • 2018-12-27
      • 2020-01-23
      • 2016-07-22
      • 1970-01-01
      相关资源
      最近更新 更多