JOOQ配置

JOOQ

在gradle中配置有几种方式

1、build.gradle(使用Configuration配置)

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

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }  
dependencies {
        classpath 'org.jooq:jooq-codegen:3.14.15'
    }
}
plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.4.32'
    id 'war'
}

group 'com.wh'
version '1.0-SNAPSHOT'
repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
    testImplementation 'junit:junit:4.11'
    implementation 'mysql:mysql-connector-java:8.0.25'
    implementation 'org.jooq:jooq-meta:3.14.15'
    implementation 'org.jooq:jooq:3.14.15'
}

task jooqCodeGenerate {
    doLast {
        Configuration config = new Configuration()
                .withJdbc(new Jdbc()
                        .withDriver('com.mysql.cj.jdbc.Driver')
                        .withUrl('')
                        .withUsername('root')
                        .withPassword('root'))
                .withGenerator(new Generator()
                .withGenerator(new Generator()
                        .withGenerate(new Generate()
                                .withRelations(true)
                                .withImmutablePojos(false) // if true, cannot use 'into()' method
                                .withInterfaces(true)
                                .withDaos(true))
                        .withDatabase(new Database()
                                .withName('org.jooq.meta.mysql.MySQLDatabase')
                                .withIncludes('.*')
                                .withInputSchema('')
                        )
                        .withTarget(new Target()
                                .withPackageName('gradle.db')
                                .withDirectory('src/main/kotlin')))
        GenerationTool.generate(config as Configuration)
    }
}

2、build.gradle(使用xml文件配置)


task jooqGenerate {
    doLast() {
        def writer = new StringWriter()
        new MarkupBuilder(writer)
        		//这里版本必须是以  .0结尾
                .configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd') {
                    jdbc() {
                        driver('com.mysql.cj.jdbc.Driver')
                        url('')
                        user('root')
                        password('root')
                    }
                    generator() {
                        database {
                            name('org.jooq.meta.mysql.MySQLDatabase')
                            includes('.*')
                            excludes()
                            unsignedTypes(false)
                            inputSchema('')
                            includeTables(true)
                            includeKeys(false)
                            integerDisplayWidths(false)
                            includeRoutines(false)
                            includePackages(false)
                            includeUDTs(false)
                            includeSequences(false)

                        }
                        generate([:]) {
                            deprecated(false)
                            records(true)
                            interfaces(false)
                            relations(false)
                            fluentSetters(true)
                            pojos(true)
                            daos(false)
                            javaTimeTypes(true)
                        }
                        target() {
                            packageName('com.dataaccess.db')
                            directory("src/main/java")
                        }
                    }
                }
        GenerationTool.generate(writer.toString())
    }
}

3、build.gradle.kts

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jooq.codegen.GenerationTool
import org.jooq.meta.jaxb.*

plugins {
    id("org.springframework.boot") version "2.6.0"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.6.0"
    kotlin("plugin.spring") version "1.6.0"
}
group = "rin"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenCentral()
}

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.jooq:jooq-codegen:3.14.15")
        classpath("mysql:mysql-connector-java:8.0.27")
    }
}
dependencies {

    implementation("org.springframework.boot:spring-boot-starter-jooq")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    runtimeOnly("mysql:mysql-connector-java:8.0.27")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    implementation("org.jooq:jooq:3.14.15")
    implementation("org.jooq:jooq-codegen:3.14.15")
    implementation("org.jooq:jooq-meta:3.14.15")
}

tasks.register("JOOQ_Code_Generate") {
    doLast{
        val config: org.jooq.meta.jaxb.Configuration = Configuration()
            .withJdbc(Jdbc()
                .withDriver("com.mysql.cj.jdbc.Driver")
                .withUrl("")
                .withUsername("root")
                .withPassword("root"))
            .withGenerator(Generator()
                .withGenerate(Generate()
                    .withComments(true) // 注释 √
                    .withCommentsOnCatalogs(true)
                    .withRelations(true)
                    .withImmutablePojos(false) // if true, cannot use 'into()' method
                    .withInterfaces(true)
                    .withDaos(true))
                .withDatabase(Database()
                    .withName("org.jooq.meta.mysql.MySQLDatabase")
                    .withIncludes(".*")
                    .withExcludes("")
                    .withInputSchema("")
                )
                .withTarget(org.jooq.meta.jaxb.Target()
                    .withPackageName("")
                    .withDirectory("src/main/java"))
            )
        GenerationTool.generate(config)
    }
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值