我已经获得了一个Ratpack应用程序,该应用程序使用gradle(v2.1.0)和jooq(v3.8.1)生成了类文件。
这是我的 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 块不在顶部,这在我的终端机和在线版本中都是不允许的:
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
有人可以告诉我是否:
答案 0 :(得分:2)
实际上,由于即将实现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.*
请注意,架构名称区分大小写,因此可能有助于替换它:
inputSchema = 'public'
以此
inputSchema = 'PUBLIC'
您早前已将其更正:.withInputSchema("PUBLIC")