【问题标题】:Cannot resolve class TableOptions generated by jOOQ无法解析 jOOQ 生成的类 TableOptions
【发布时间】:2020-11-14 08:24:01
【问题描述】:

我正在使用带有 Gradle 的 jOOQ 3.13.0。

以下是来自build.gradle的一些相关摘录

...

buildscript {
    dependencies {
        classpath 'org.jooq:jooq-codegen:3.13.3'
        classpath 'org.postgresql:postgresql:42.2.5'
    }
}

...

dependencies {
    compile 'org.jooq:jooq:3.13.3'
}

...

def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
        .configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd') {
            jdbc() {
                driver('org.postgresql.Driver')
                url('jdbc:postgresql://localhost:5432/metrics')
                user('postgres')
                password('pwd')
            }
            generator() {
                database() {
                    inputSchema('public')
                }

                // Watch out for this caveat when using MarkupBuilder with "reserved names"
                // - https://github.com/jOOQ/jOOQ/issues/4797
                // - http://stackoverflow.com/a/11389034/521799
                // - https://groups.google.com/forum/#!topic/jooq-user/wi4S9rRxk4A
                generate() {
                }
                target() {
                    packageName('metrics.jooq')
                    directory('src/main/java')
                }
            }
        }

在我运行 gradle clean build 后,它成功生成了代码,但无法编译,因为它包含:

import org.jooq.TableOptions;

无法解决。我该如何解决这个问题。很奇怪,它生成的代码无法编译...

我注意到 Gradle 出于某种原因下载了 3.11.9 版而不是 3.13.3 版。

之后,我在build.gradle 中将所有 jooq 相关版本更改为 3.11.9(也是 xsd 版本)并运行构建但得到:

Error while reading XML configuration

这是堆栈跟踪的结尾:

...
Caused by: org.jooq.codegen.GeneratorException: Error while reading XML configuration
        at org.jooq.codegen.GenerationTool.load(GenerationTool.java:931)
        at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:218)
        at org.jooq.codegen.GenerationTool$generate.call(Unknown Source)
        at build_abyn1owj8gv09akc1mcgpsxr1.run(/media/wd/job/otr/mk/ufos-portal-incubate/solutions/mk-dashboard/build.gradle:56)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
        ... 104 more
Caused by: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
        at org.jooq.codegen.GenerationTool.load(GenerationTool.java:914)
        ... 108 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
        ... 109 more

我尝试按照这里的建议解决它

https://github.com/jOOQ/jOOQ/issues/9066

并添加到build.gradle

    dependencies {
        classpath group: 'com.sun.xml.bind', name: 'jaxb-core', version: '3.0.0-M4'
        classpath group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '3.0.0-M4'
        classpath group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
...

但没有成功

【问题讨论】:

    标签: gradle code-generation jooq


    【解决方案1】:

    我已经通过使用正确的依赖项解决了这个问题

    这是build.gradle的摘录

    buildscript {
       dependencies {
            classpath group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
            classpath group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0.1'
            classpath group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.1'
    
            classpath 'org.jooq:jooq-codegen:3.11.9'
            classpath 'org.postgresql:postgresql:42.2.5'
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-08
      • 2017-07-18
      • 2017-08-15
      • 2019-11-16
      • 2018-03-29
      • 2021-12-29
      • 2021-01-27
      • 2021-01-22
      相关资源
      最近更新 更多