JOOQ配置
JOOQ
1、build.gradle(使用Configuration配置)
import org.jooq.codegen.GenerationToolimport 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.KotlinCompileimport org.jooq.codegen.GenerationToolimport 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_8repositories { 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()}
开发者涨薪指南 48位大咖的思考法则、工作方式、逻辑体系