3
votes

I have sbt task which generates jooq code

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"

Here is 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>

I use scala 2.12.4

Code generated fine.

But when I compile project, getting compilation error.

.../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)

When I tried to downgrade to scala 2.12.3, it works fine.

Is there any solution to make it work with scala 2.12.4?

I do not want to downgrade scala version. It starts to frustate me, even minor versions (2.12.4 - 2.12.3) are not backward compatible??

1

1 Answers

1
votes

This is a known regression in the Scala 2.12.4 compiler. A workaround is documented here: https://github.com/jOOQ/jOOQ/issues/6875

You can post process the generated jOOQ code as such, until the compiler issue is fixed in 2.12.5:

Search

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

Replace

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