gpt4 book ai didi

gradle - 新的 jooq/gradle 配置不生成任何 jooq 类

转载 作者:行者123 更新时间:2023-12-03 03:47:17 27 4
gpt4 key购买 nike

我得到了一个使用 gradle (v2.1.0) 和 jooq (v3.8.1) 生成类文件的 Ratpack 应用程序。

这是我的 build.gradle 文件:

buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.ratpack:ratpack-gradle:1.5.4"
classpath "com.github.jengelman.gradle.plugins:shadow:1.2.3"
classpath "mysql:mysql-connector-java:5.1.34"
classpath 'org.jooq:jooq-codegen:3.8.1'
classpath 'com.h2database:h2:1.4.186'
}
}

plugins {
id "com.github.michaelruocco.embedded-mysql-plugin" version "2.1.7"
}

apply plugin: "io.ratpack.ratpack-java"
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "idea"

// db dump: mysqldump -P 3306 -h 127.0.0.1 -u embedded_user -ppassword --all-databases
def RDS_HOSTNAME = "localhost"
def RDS_PORT = 3306
def RDS_DB_NAME = "test"
def RDS_USERNAME = "embedded_user"
def RDS_PASSWORD = "password"

run {
environment "RDS_HOSTNAME", RDS_HOSTNAME
environment "RDS_PORT", RDS_PORT
environment "RDS_DB_NAME", RDS_DB_NAME
environment "RDS_USERNAME", RDS_USERNAME
environment "RDS_PASSWORD", RDS_PASSWORD
}

repositories {
jcenter()
}

ext {
ratpackPac4jVersion="2.0.0"
ratpackVersion="1.5.1"
pac4jVersion="2.1.0"
}

embeddedMysql {
url = 'jdbc:mysql://' + RDS_HOSTNAME + ':' + RDS_PORT + "/" + RDS_DB_NAME
username = RDS_USERNAME
password = RDS_PASSWORD
version = 'v5_7_latest'
}

import org.jooq.util.jaxb.*
import org.jooq.util.*

task jooqCodegen {
doLast {
String init = "$projectDir/src/main/resources/init.sql".replaceAll('\\\\', '/')
Configuration configuration = new Configuration()
.withJdbc(new Jdbc()
.withDriver("org.h2.Driver")
.withUrl("jdbc:h2:mem:todo;INIT=RUNSCRIPT FROM '$init'")
)
.withGenerator(new Generator()
.withDatabase(new Database()
.withName("org.jooq.util.h2.H2Database")
.withIncludes(".*")
.withExcludes("")
.withInputSchema("PUBLIC")
)
.withTarget(new Target()
.withDirectory("$projectDir/src/main/auto_generated")
.withPackageName("jooq")))
GenerationTool.generate(configuration)
}
}

run.dependsOn startEmbeddedMysql

dependencies {
runtime "org.slf4j:slf4j-simple:1.7.25"

compile "org.pac4j:ratpack-pac4j:${ratpackPac4jVersion}"
compile "io.ratpack:ratpack-groovy:${ratpackVersion}"
compile "io.ratpack:ratpack-test:${ratpackVersion}"
compile "org.pac4j:pac4j-core:${pac4jVersion}"
compile "org.pac4j:pac4j-oauth:${pac4jVersion}"
compile "org.pac4j:pac4j-openid:${pac4jVersion}"
compile "org.pac4j:pac4j-http:${pac4jVersion}"
compile "org.pac4j:pac4j-gae:${pac4jVersion}"
compile "org.pac4j:pac4j-oidc:${pac4jVersion}"
compile "org.pac4j:pac4j-jwt:${pac4jVersion}"
compile ratpack.dependency('hikari')
compile "ch.qos.logback:logback-classic:1.0.13"
compile group: 'io.ratpack', name: 'ratpack-thymeleaf', version: '1.4.0-rc-3'
compile "mysql:mysql-connector-java:5.1.34"
compile 'org.jooq:jooq:3.8.1'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.2.Final'

}

mainClassName = "xyz.mealsahead.Main"

我开始使用 jooq API 并意识到我使用的是旧版本的 jooq,所以想切换到较新的 API。

我尝试的第一件事是将两个 jooq 引用从 3.8.1 更改为 3.11.2。这引起了问题,因为 jooq 版本似乎更改了 API,使得 jooq 配置不再起作用:
> startup failed:
build file build.gradle': 72: unable to resolve class Target
@ line 72, column 19.
.withTarget(new Target()
^

build file build.gradle': 66: unable to resolve class Database
@ line 66, column 23.
.withDatabase(new Database()
^

build file build.gradle': 65: unable to resolve class Generator
@ line 65, column 22.
.withGenerator(new Generator()
^

etc.

jooq 有一个 gradle 设置示例,但我不明白它是如何工作的: https://www.jooq.org/doc/3.11/manual/code-generation/codegen-gradle/ .奇怪的是该示例中的 buildscript block 不在顶部,从我在终端和在线看到的内容来看,这是不允许的:
build.gradle': 24: only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed

所以我不知道该示例将如何工作,除非它适用于与我(之前或之后)不同的 gradle 版本。

查看 jooq-gradle 插件 ( https://github.com/etiennestuder/gradle-jooq-plugin) 的文档,它有非常清晰的设置 gradle 脚本的步骤,所以我修改了 build.gradle 文件,如下所示:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.ratpack:ratpack-gradle:1.5.4"
classpath "com.github.jengelman.gradle.plugins:shadow:1.2.3"
classpath "mysql:mysql-connector-java:5.1.34"
classpath 'com.h2database:h2:1.4.186'
classpath 'nu.studer:gradle-jooq-plugin:3.0.1'
}
}

plugins {
id "com.github.michaelruocco.embedded-mysql-plugin" version "2.1.7"
}

apply plugin: 'nu.studer.jooq'
apply plugin: "io.ratpack.ratpack-java"
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "idea"

// db dump: mysqldump -P 3306 -h 127.0.0.1 -u embedded_user -ppassword --all-databases
def RDS_HOSTNAME = "localhost"
def RDS_PORT = 3306
def RDS_DB_NAME = "test"
def RDS_USERNAME = "embedded_user"
def RDS_PASSWORD = "password"

run {
environment "RDS_HOSTNAME", RDS_HOSTNAME
environment "RDS_PORT", RDS_PORT
environment "RDS_DB_NAME", RDS_DB_NAME
environment "RDS_USERNAME", RDS_USERNAME
environment "RDS_PASSWORD", RDS_PASSWORD
}

repositories {
jcenter()
}

ext {
ratpackPac4jVersion="2.0.0"
ratpackVersion="1.5.1"
pac4jVersion="2.1.0"
}

embeddedMysql {
url = 'jdbc:mysql://' + RDS_HOSTNAME + ':' + RDS_PORT + "/" + RDS_DB_NAME
username = RDS_USERNAME
password = RDS_PASSWORD
version = 'v5_7_latest'
}

dependencies {
jooqRuntime 'com.h2database:h2:1.4.193'
}

jooq {
String init = "$projectDir/src/main/resources/init.sql".replaceAll('\\\\', '/')

version = '3.11.2'
edition = 'OSS'
sample(sourceSets.main) {
jdbc {
driver = "org.h2.Driver" //'org.postgresql.Driver'
url = "jdbc:h2:mem:todo;INIT=RUNSCRIPT FROM '$init'" //'jdbc:postgresql://localhost:5432/sample'
user = 'sa'
password = ''
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
database {
name = 'org.jooq.meta.h2.H2Database'
includes = '.*'
excludes = ''
inputSchema = 'public'
}
generate {
relations = true
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
}
target {
directory = "$projectDir/src/main/auto_generated"
packageName = 'jooq'
}
}
}
}

run.dependsOn startEmbeddedMysql

dependencies {
runtime "org.slf4j:slf4j-simple:1.7.25"

compile "org.pac4j:ratpack-pac4j:${ratpackPac4jVersion}"
compile "io.ratpack:ratpack-groovy:${ratpackVersion}"
compile "io.ratpack:ratpack-test:${ratpackVersion}"
compile "org.pac4j:pac4j-core:${pac4jVersion}"
compile "org.pac4j:pac4j-oauth:${pac4jVersion}"
compile "org.pac4j:pac4j-openid:${pac4jVersion}"
compile "org.pac4j:pac4j-http:${pac4jVersion}"
compile "org.pac4j:pac4j-gae:${pac4jVersion}"
compile "org.pac4j:pac4j-oidc:${pac4jVersion}"
compile "org.pac4j:pac4j-jwt:${pac4jVersion}"
compile ratpack.dependency('hikari')
compile "ch.qos.logback:logback-classic:1.0.13"
compile group: 'io.ratpack', name: 'ratpack-thymeleaf', version: '1.4.0-rc-3'
compile "mysql:mysql-connector-java:5.1.34"
compile 'org.jooq:jooq'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.2.Final'

}

mainClassName = "xyz.mealsahead.Main"

运行“gradle run”工作正常,所以我假设它正在下载新版本的 jooq,但现在我没有看到任何代码生成。我看到以下消息:
$ gradle generateSampleJooqSchemaSource 
:generateSampleJooqSchemaSource UP-TO-DATE

有人可以告诉我,如果我:
  • 正在为此使用适当的 gradle-jooq 插件吗?
  • 是否错误地配置了以前版本的新生成器语法?
  • 最佳答案

    关于您手动设置 jOOQ 代码生成器

    事实上,由于即将到来的 jOOQ 3.12 模块化,一些拆分包必须重新命名,即 org.jooq.util包裹。在您的手动设置中,您需要从以下位置更改导入:

    import org.jooq.util.jaxb.*
    import org.jooq.util.*


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

    关于您使用第三方 Gradle 插件

    请注意,模式名称区分大小写,因此可能有助于替换它:
    inputSchema = 'public'

    这样
    inputSchema = 'PUBLIC'

    您之前已经正确了: .withInputSchema("PUBLIC")

    关于gradle - 新的 jooq/gradle 配置不生成任何 jooq 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51414954/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com