jOOQ maven插件生成代码异常

[已解决]java.lang.ClassNotFoundException: org.jooq.util.mysql.MySQLDatabase。

See https://github.com/jOOQ/jOOQ/issues/7419。

一般是由高版本jdk引起的java模块化(JPMS)异常提示。

问题根源在于依赖包命名不规范所致,如:多个jar包都使用了相同的包名。

jOOQ早期版本都存在包名冲突问题(相对java9模块化规范而言)

jooq
jooq-meta
jooq-codegen

这些包中都包含了org.jooq.util包。

在java还未采用模块化之前这是没有问题的,在Java 9/JPMS后行不通的。

在jOOQ后期版本中对包作了重新规划,具体如下:

jooq-meta: org.jooq.meta
jooq-meta-extensions: org.jooq.meta.extensions
jooq-codegen: org.jooq.codegen
jooq-codegen-maven: org.jooq.codegen.maven

MySQLDatabase在jOOQ早期版本中出现在org.jooq.util下,按java 9/JPMS规范重新规划后,被安排在org.jooq.meta包下。

使用jOOQ时出现此类问题直接修改包名即可解决,或使用最新版本jOOQ

以下是jOOQ异常示例:

[ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.11.9:generate (default) on project web: Error running jOOQ code generation tool: Your configured org.jooq.util type was not found.
[ERROR] Do note that in jOOQ 3.11, jOOQ-meta and jOOQ-codegen packages have been renamed. New package names are:
[ERROR] - org.jooq.meta
[ERROR] - org.jooq.meta.extensions
[ERROR] - org.jooq.codegen
[ERROR] - org.jooq.codegen.maven
[ERROR] See https://github.com/jOOQ/jOOQ/issues/7419 for details: org.jooq.util.mysql.MySQLDatabase
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jooq:jooq-codegen-maven:3.11.9:generate (default) on project web: Error running jOOQ code generation tool
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)

Caused by: org.apache.maven.plugin.MojoExecutionException: Error running jOOQ code generation tool
    at org.jooq.codegen.maven.Plugin.execute(Plugin.java:200)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more
Caused by: java.lang.ClassNotFoundException: Your configured org.jooq.util type was not found.
Do note that in jOOQ 3.11, jOOQ-meta and jOOQ-codegen packages have been renamed. New package names are:
- org.jooq.meta
- org.jooq.meta.extensions
- org.jooq.codegen
- org.jooq.codegen.maven
See https://github.com/jOOQ/jOOQ/issues/7419 for details
    at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:857)
    at org.jooq.codegen.GenerationTool.run(GenerationTool.java:364)
    ... 22 more
Caused by: java.lang.ClassNotFoundException: org.jooq.util.mysql.MySQLDatabase
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:821)
    ... 25 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException