我将为您翻译以下内容:
我正在尝试使用Kotlin DSL在Gradle中设置JOOQ代码生成,但是当我运行生成器任务时,出现错误“无法实例化注释类”。我错过了什么吗?
这是build.gradle.kts文件的内容:
import org.jooq.meta.jaxb.*
import org.jooq.codegen.GenerationTool
plugins {
id("java")
id("java-library")
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jooq:jooq-codegen:3.16.6")
classpath("org.postgresql:postgresql:42.3.5")
}
}
repositories {
google()
mavenCentral()
}
dependencies {
compileOnly("org.jooq:jooq:3.16.6")
compileOnly("org.jooq:jooq-codegen:3.16.6")
runtimeOnly("org.postgresql:postgresql:42.3.5")
}
group = "com.example"
version = "1.0-SNAPSHOT"
// Set the following system properties to enable JOOQ to connect to the DB
// -Djooq.codegen.jdbc.user
// -Djooq.codegen.jdbc.password
//
tasks.create("generate") {
GenerationTool.generate(Configuration()
.withJdbc(Jdbc()
.withDriver("org.postgresql.Driver")
.withUrl("jdbc:postgresql://localhost:5432/postgres"))
.withGenerator(Generator()
.withDatabase(Database().withInputSchema("public"))
.withGenerate(Generate())
.withTarget(Target()
.withPackageName("com.example.db")
.withDirectory("src/generated/jooq"))))
}
以下是堆栈跟踪信息:
ScriptCompilationException(errors=[ScriptCompilationError(message=Annotation class cannot be instantiated, location=/Users/foo/.gradle/.tmp/gradle-kotlin-dsl-12544449971161496170.tmp/build.gradle.kts (51:33)), ScriptCompilationError(message=Unresolved reference: withPackageName, location=/Users/foo/.gradle/.tmp/gradle-kotlin-dsl-12544449971161496170.tmp/build.gradle.kts (52:30))])
at org.gradle.kotlin.dsl.support.KotlinCompilerKt.compileKotlinScriptModuleTo(KotlinCompiler.kt:187)
at org.gradle.kotlin.dsl.support.KotlinCompilerKt.compileKotlinScriptToDirectory(KotlinCompiler.kt:148)
at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$compileScript$1.invoke(ResidualProgramCompiler.kt:708)
[snipped 100+ lines]
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:84)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
Target
,它恰好是一个注释。检查一下你是否使用了正确的目标类。 - Jornimport org.jooq.meta.jaxb.Target
?那个类并不特殊,例如与Generate
或Database
或该包中的其他类相比。 - Lukas Eder