gpt4 book ai didi

scala - jooq + scala 代码生成 : method createIndex in object AbstractKeys cannot be accessed in object org. jooq.impl.AbstractKeys

转载 作者:行者123 更新时间:2023-12-01 17:29:06 25 4
gpt4 key购买 nike

我有生成 jooq 代码的 sbt 任务

val generateJOOQ = taskKey[Seq[File]]("Generate JooQ classes")

val generateJOOQTask = (sourceManaged, fullClasspath in Compile, runner in Compile, streams) map { (src, cp, r, s) =>
toError(r.run("org.jooq.util.GenerationTool", cp.files, Array("conf/jooq.xml"), s.log))
((src / "main/generated") ** "*.scala").get
}

generateJOOQ <<= generateJOOQTask

unmanagedSourceDirectories in Compile += sourceManaged.value / "main/generated"

这里是jooq.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.10.4.xsd">
<jdbc>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost/postgres</url>
<user>postgres</user>
<password>postgres</password>
</jdbc>
<generator>
<name>org.jooq.util.ScalaGenerator</name>
<database>
<name>org.jooq.util.postgres.PostgresDatabase</name>
<inputSchema>public</inputSchema>
<includes>.*</includes>
<excludes></excludes>
</database>
<target>
<packageName>generated</packageName>
<directory>target/scala-2.12/src_managed/main</directory>
</target>
</generator>
</configuration>

我使用 scala 2.12.4

代码生成正常。

但是当我编译项目时,出现编译错误。

.../scala-2.12/src_managed/main/generated/Indexes.scala:58: method createIndex in object AbstractKeys cannot be accessed in object org.jooq.impl.AbstractKeys [error] Access to protected method createIndex not permitted because [error] prefix type org.jooq.impl.AbstractKeys.type does not conform to [error] object Indexes0 in object Indexes where the access takes place [error] val PENDING_USERS_EMAIL_IDX : Index = AbstractKeys.createIndex("pending_users_email_idx", PendingUsers.PENDING_USERS, ArrayOrderField [_] , false)

当我尝试降级到 scala 2.12.3 时,它工作正常。

是否有任何解决方案可以使其与 scala 2.12.4 一起使用?

我不想降级 scala 版本。它开始让我感到沮丧,即使是次要版本 (2.12.4 - 2.12.3) 也不向后兼容??

最佳答案

这是 Scala 2.12.4 编译器中的已知回归。此处记录了解决方法:https://github.com/jOOQ/jOOQ/issues/6875

您可以像这样对生成的 jOOQ 代码进行后处理,直到编译器问题在 2.12.5 中得到修复:

搜索

AbstractKeys.createUniqueKey(TAuthor.T_AUTHOR, "PK_T_AUTHOR", TAuthor.T_AUTHOR.ID)

替换

org.jooq.tools.reflect.Reflect.on(classOf[AbstractKeys])
.call("createUniqueKey", TAuthor.T_AUTHOR, "PK_T_AUTHOR", TAuthor.T_AUTHOR.ID).get()

关于scala - jooq + scala 代码生成 : method createIndex in object AbstractKeys cannot be accessed in object org. jooq.impl.AbstractKeys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48336928/

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