使用Gradle的Spring项目。我将OpenApiGenerate与QueryDsl结合使用(与Spring MongoDB结合使用)。
gradle clean构建有时会在本地失败,并且始终在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 {
                                           ^

Here's the gradle build file:

// 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
}}
}

09-25 13:35