微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Quarkus 微服务中基于 XSD 生成 XJC 类导致 quarkusGenerateCode FAILURE

如何解决在 Quarkus 微服务中基于 XSD 生成 XJC 类导致 quarkusGenerateCode FAILURE

我有一个 Quarkus 微服务,我正在使用 XJC Gradle 任务从 XSD 模式中生成 java 类,如下所示: (它基于这篇文章的第二个答案:How to generate jaxb classes from xsd using gradle,jaxb and xjc,classes should have XmlRootElement

// The folter to put the generated XJC Java classes in
def generatedXjcclassesDir = "src/generated/java"

sourceSets {
    generated {
        java.srcDir generatedXjcclassesDir
    }
}

dependencies {
    // Also compile the generated XJC Java classes
    compile sourceSets.generated.output

    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
    generatedCompile 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
}

/**
 * XJC stuff
 *
 **/
configurations {
    // Having a separate configuration for XJC plugin only
    xjc
}

dependencies {
    xjc 'org.glassfish.jaxb:jaxb-xjc:2.3.3'
}

def xjcTask(taskName,schema,pkg,dest) {

    // Create (if not existing yet) the destination directory
    file(dest).mkdirs()

    // Calling XJCFacade which is the entry point of the XJC JAR
    tasks.create(name: taskName,type: JavaExec) {
        classpath configurations.xjc
        main 'com.sun.tools.xjc.XJCFacade'

        // To explore available args,download the XJC JAR manually and run java -jar jaxb-xjc.jar --help
        args schema,"-p","-d",dest
    }
    // 
    compileGeneratedJava.dependsOn tasks.getByName(taskName)
}

xjcTask('xjcSchema1','src/main/xsd/SCL.xsd','org.lfenergy.compas',generatedXjcclassesDir)

它确实工作得很好,所有的 java 类都被生成并放入 src/generated/java 文件夹中。

但是 quarkus 应用程序没有正确编译,因为它给出了以下错误

> Task :quarkusGenerateCode Failed
Caching disabled for task ':quarkusGenerateCode' because:
  Build cache is disabled
Task ':quarkusGenerateCode' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
preparing quarkus application
:quarkusGenerateCode (Thread[Execution worker for ':',5,main]) completed. Took 1.487 secs.

FAILURE: Build Failed with an exception.

* What went wrong:
Execution Failed for task ':quarkusGenerateCode'.
> Error while reading file as JAR: /Users/rob/Code/CoMPAS/compas-cim-mapping/build/resources/generated

我尝试搜索错误,但这里缺乏我的 Quarkus 知识。有人可以帮我吗? :)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。