从jOOQ 3.16和#12601开始,在你的jOOQ生成的代码中可能会出现类似这样的编译错误信息。
[ERROR] .../DefaultCatalog.java:[53,73] 找不到符号
[ERROR] 符号:变量 VERSION_3_17
[ERROR] 位置:类 org.jooq.Constants
通常情况下,这个错误在生成的代码中与其他编译错误混在一起。它的目的是帮助排除这些其他编译错误的故障。这个错误是由用户正在使用的两个jOOQ工件之间的不匹配引起的,包括:
org.jooq:jooq(运行时库)org.jooq:jooq-codegen(代码生成库)
这在上述生成代码的Javadoc中也有记录:
/**
* A reference to the 3.17 minor release of the code generator. If this
* doesn't compile, it's because the runtime library uses an older minor
* release, namely: 3.17. You can turn off the generation of this reference
* by specifying /configuration/generator/generate/jooqVersionReference
*/
private static final String REQUIRE_RUNTIME_JOOQ_VERSION =
Constants.VERSION_3_17;
就像有运行时(JDK或JRE)和代码生成器(编译器)的JDK一样,用户必须确保运行时版本总是>=代码生成版本。
如果你看到上述错误,你的maven或gradle构建中可能有这样的配置。
<!-- A runtime dependency. -->
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.16.9</version>
</dependency>
<!-- And then, later on: -->
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.17.3</version>
</plugin>
3.17版本的代码生成器生成的代码只能被3.17或更新的运行时库消耗。虽然在较新的运行时下使用较旧的代码生成器是完全可以的:
org.jooq:jooq:3.17.3org.jooq:jooq-codegen:3.16.9
上述配置不被支持:
org.jooq:jooq:3.16.9org.jooq:jooq-codegen:3.17.3
换句话说:
- 生成的代码是向前兼容的,但不向后兼容。
- 运行时API(由生成的代码使用)是向后兼容的,但不是向前兼容的。
然而,如果可能的话,建议总是匹配代码生成库和运行时库,以避免任何其他麻烦。
关掉该功能
如果这个代码生成功能困扰着你,你可以随时通过指定来关闭它:
<configuration>
<generator>
<generate>
<jooqVersionReference>false</jooqVersionReference>
</generate>
</generator>
</configuration>