简体   繁体   中英

JOOQ Doesn't Generate

I was following here . I used postgresql instead of h2 . I was able to build the project with some additional fields.

I created a package database under com.example.demo , but it was still empty after project was built.

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

Is there something I am missing? Why can I not see pojos and daos in database package? My database has only one table with 2 columns.

BUILD SUCCESSFULL when I type ./gradlew generate , but nothing gets generated.

Your file looks okay. I had a similar issue (while using maven). Try three things (that worked for me):

  1. check case of the schema in "withInputSchema" property. Try to pass uppercase PUBLIC.
  2. try to change 'src/main/java' to './src/main/java'
  3. add "includes" and pass.* in it (to generate for all tables in the schema)

You can try ./gradlew generate --info command, which will give you more information about the build process.

My gradle script is quite similar to yours. By using above command, I find out that the classes are actually generated, but in a different folder /Users/{MyUserName}/.gradle/daemon/7.1.1/src/main/java .

So I have to explicitly set the output directory with def outputDirectory = projectDir.toString() + '/src/main/java' .

This works for me


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM