通过 gradle 配置 JOOQ Codegen 时找不到 H2 驱动程序
Posted
技术标签:
【中文标题】通过 gradle 配置 JOOQ Codegen 时找不到 H2 驱动程序【英文标题】:H2 Driver not found when configuring JOOQ Codegen through gradle 【发布时间】:2020-05-30 11:41:06 【问题描述】:我正在尝试使用 h2、jooq 和 flyway 配置项目。但是,一旦nu.studer.jooq
插件生成了config.xml
,它就无法找到org.h2.driver
我在我的build.gradle
中有依赖关系,如下所示以及我不断收到的错误。
plugins
id 'java'
id 'application'
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'nu.studer.jooq' version '4.0'
id 'org.flywaydb.flyway' version '6.2.3'
ext['jooq.version'] = '3.12.3'
sourceCompatibility = 11.0
repositories
mavenCentral()
jcenter()
dependencies
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.2.4.RELEASE'
implementation group: 'org.jooq', name: 'jooq', version: '3.12.3'
implementation group: 'com.h2database', name: 'h2', version: '1.4.199'
application
mainClassName = 'exampleapp.App'
jooq
version = '3.12.3'
edition = 'OSS'
sample(sourceSets.main)
jdbc
driver = 'org.h2.Driver'
url = 'jdbc:h2:~/test'
user = 'sa'
password = ''
schema = 'public'
generator
name = 'org.jooq.util.DefaultGenerator'
strategy
name = 'org.jooq.util.DefaultGeneratorStrategy'
database
name = 'org.jooq.meta.h2.H2Database'
generate
relations = true
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
target
packageName = 'generated.jooq'
directory = '$projectDir/src/generated/jooq'
flyway
url = 'jdbc:h2:~/test'
user = 'sa'
password = ''
schemas = ['public']
generateSampleJooqSchemaSource.dependsOn flywayMigrate
我运行gradle clean build
时收到的错误如下:
java.lang.ClassNotFoundException: org.h2.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.jooq.codegen.GenerationTool.loadClass0(GenerationTool.java:925)
at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:869)
at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:334)
at org.jooq.codegen.GenerationTool.run(GenerationTool.java:221)
at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:216)
at org.jooq.codegen.GenerationTool.main(GenerationTool.java:188)
不知道为什么它在类路径中找不到 h2,有什么想法吗?
【问题讨论】:
【参考方案1】:想通了,我需要添加
jooqRuntime
dependecies: 'com.h2database:h2:1.4.199'
允许任务在类路径中找到 org.h2.Driver
【讨论】:
以上是关于通过 gradle 配置 JOOQ Codegen 时找不到 H2 驱动程序的主要内容,如果未能解决你的问题,请参考以下文章
尝试更新到“org.jooq:jooq-codegen-maven:3.15.1”时构建失败