Slackbot
04/04/2022, 4:42 PMVampire
04/04/2022, 5:14 PMsourceFolder
config option which is by default set to src/main/kotlin
for the kotlin
generator. My guess is that if you have to add src/commonMain/kotlin
, that this is actually configured that way, except if the documented default value is wrong.
I also don't like the generated sources to be an own Gradle build, but incorporate it in the existing build, so I also suppress almost all other generated files like the Gradle project files and configure the sourceFolder
to be empty and thus directly the output directory.
This is how I do it, though it is using the Java generator, as I don't like the result of the Kotlin generator for its overuse of static state / companion object state, which is has pretty negative side-effects in my case:
val openApiGeneratorIgnoreFile = layout.projectDirectory.file(".openapi-generator-ignore")
openApiGenerate {
generatorName.set("java")
outputDir.set(layout.buildDirectory.dir("generated/sources/openapi/main/java").map {
it.asFile.absolutePath
})
inputSpec.set(downloadNexusOpenApiSpec.map {
it.outputs.files.singleFile.absolutePath
})
generateApiDocumentation.set(false)
generateApiTests.set(false)
generateModelDocumentation.set(false)
generateModelTests.set(false)
invokerPackage.set("org.sonatype.nexus.client")
apiPackage.set("org.sonatype.nexus.client.api")
modelPackage.set("org.sonatype.nexus.client.model")
configOptions.set(mapOf(
"sourceFolder" to "",
"dateLibrary" to "java8"
))
ignoreFileOverride.set(
openApiGeneratorIgnoreFile.asFile.absolutePath
)
}
// work-around for <https://github.com/OpenAPITools/openapi-generator/issues/10214>
tasks.openApiGenerate {
inputs
.files(openApiGeneratorIgnoreFile)
.withPathSensitivity(NONE)
.withPropertyName("openApiGeneratorIgnoreFile")
}
pluginManager.withPlugin("idea") {
configure<IdeaModel> {
module {
generatedSourceDirs.addAll(tasks.openApiGenerate.get().outputs.files)
}
}
}
sourceSets {
main {
java {
srcDir(tasks.openApiGenerate)
}
}
}
Christoph Sturm
04/05/2022, 1:15 PMChristoph Sturm
04/05/2022, 1:24 PM% ls build/openapi/generated
src
Vampire
04/05/2022, 5:34 PM.openapi-generator-ignore
file already?
Or maybe you use a version where the result is different.
🤷♂️
But the remaining points stay valid.Christoph Sturm
04/05/2022, 6:19 PM