Spring Gradle queryDsl 任务在 OpenApiGenerate 后失败

Spring Gradle task for queryDsl fails after OpenApiGenerate

Spring 项目使用 Gradle。我将 OpenApiGenerate 与 QueryDsl 结合使用(与 Spring MongoDB 一起使用)。 gradle clean build 有时会在本地失败,但总是在 Gitlab 上失败-CI:

Successfully generated code to task ':backend:openApiGenerate' property 'outputDir'
34 errors
> Task :backend:querydsl FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':backend:querydsl'.

QueryDsl 失败,因为它找不到由 OpenApiGenerate 生成的源:

 public class SomethingController implements SomethingApi {
                                           ^

这是 gradle 构建文件:

// QueryDSL
configurations {
    querydslapt.extendsFrom compileClasspath
}
dependencies {
    querydslapt 'com.querydsl:querydsl-apt:4.3.1'
}
task querydsl(type: JavaCompile, group: 'build', description: 'Generate the QueryDSL query types') {
    source = sourceSets.main.java
    classpath = configurations.compile + configurations.querydslapt
    options.annotationProcessorPath = configurations.compile + configurations.querydslapt
    options.compilerArgs = [
            '-proc:only', //only annotations
            '-processor', 'org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor'
    ]
    destinationDir = file("${buildDir}/generated/src/main/java")
}
compileJava.dependsOn querydsl

// OpenAPI
openApiValidate {
    inputSpec = "${rootDir}/openapi/specifications/schema.yaml".toString()
}
openApiGenerate {
    generatorName = "spring"
    library = "spring-boot"
    inputSpec = "${rootDir}/openapi/specifications/schema.yaml".toString()
    outputDir = "${buildDir}/generated".toString()
    systemProperties = [
            modelDocs      : "false",
            models         : "",
            apis           : "",
            supportingFiles: "false"
    ]
    configOptions = [
            useOptional          : "true",
            swaggerDocketConfig  : "false",
            performBeanValidation: "false",
            useBeanValidation    : "false",
            useTags              : "true",
            singleContentTypes   : "true",
            basePackage          : "...api",
            configPackage        : "...api",
            title                : rootProject.name,
            java8                : "false",
            dateLibrary          : "java8",
            serializableModel    : "true",
            artifactId           : rootProject.name,
            apiPackage           : "...api",
            modelPackage         : "...model",
            invokerPackage       : "...api",
            interfaceOnly        : "true"
    ]
}
compileJava.dependsOn 'openApiGenerate'

没有帮助的进一步更改:

已删除

compileJava.dependsOn 'openApiGenerate'
compileJava.dependsOn querydsl

并添加

compileJava.dependsOn querydsl
querydsl.mustRunAfter 'openApiGenerate'

有人有想法吗?特别是为什么这有时在本地有效有时无效?

openApiGenerate 任务的输出目录是否以某种方式添加到 src 目录?如果没有,你应该

sourceSets{
main{
java{
dir openApiGenerate.outputDir
}} 
} 

有用的是将 querydsl 的 destinationDir 更改为其他内容:

destinationDir = file("${buildDir}/generated/src/main/java")

destinationDir = file("${buildDir}/generated/src/main/java/querydsl")

=> openApiGenerate 似乎在初始 destinationDir 上强制执行了锁定状态,因为它由两个任务共享。