Spring project using Gradle. I'm using OpenApiGenerate in combination with QueryDsl (to use with Spring MongoDB). gradle clean build fails sometimes locally and always on 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 fails because it can't find sources generated by 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'
Further changes that did not help:
Removed
compileJava.dependsOn 'openApiGenerate'
compileJava.dependsOn querydsl
and added
compileJava.dependsOn querydsl
querydsl.mustRunAfter 'openApiGenerate'
Does anyone have an idea? specifically on why does this sometimes work locally and sometimes not?
What helped was changing destinationDir of querydsl to something else:
destinationDir = file("${buildDir}/generated/src/main/java")
to
destinationDir = file("${buildDir}/generated/src/main/java/querydsl")
=> There seems to have been a locking state enforced by openApiGenerate on the initial destinationDir since it was shared by both tasks.