Open AnonymousVovus opened 3 years ago
up )
I second this. To this day I do not understand the purpose of the gradle plugin. One would expect this plugin to automatically include the generated code to /src/gen/java
(not literally, but make the generated code part of a java sourceSet
) of the gradle project that uses the plugin, and also extend the compileClasspath
configuration to include the necessary dependencies (like jackson and stuff). But in fact, the Gradle plugin is a very thin wrapper around the CLI. You can just as well call this directly via javaExec
.
To actually use the generated code inside your own gradle project, you have to do hacky stuff like sourceSets.main.java.srcDir "${buildDir}/generated/src/main/java"
and also manually (!) copy the dependencies from the generated build.gradle file into your own.
We have tens of developers in our company, and every single one of them misunderstands the purpose of the gradle plugin. All one of them, myself included, expect this plugin to make it so that the generated code becomes directly usable inside your own gradle project. But unfortunately, this is not the case.
What we would like to have:
Just to confirm: this is not something that is already possible right?
I'm trying to at least include the generated project as a sub-project, but that fails.
I adjusted my kotlin version to match the currently used 5.1, but thats not enough.
The main project uses gradle 7.1.1 vs gradle 6.8.3 on the generated project.
Managed to make it run with an extra task that removes the wrapper { .... }
portion of the build.gradle file.
Clearly people who want to use the gradle plugin will have use-cases like me and the others in this issue where we are not interested in generating a separate gradle project.
However I would assume that it's not trivial to solve this issue, simply due to the fact that other people might want use it to build for other targets than kotlin or java (where gradle projects are generated).
Here an example how to make it work with the Java generator:
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
)
}
// TODO: work-around for https://github.com/OpenAPITools/openapi-generator/issues/10214
tasks.openApiGenerate {
inputs
.files(openApiGeneratorIgnoreFile)
.withPathSensitivity(NONE)
.withPropertyName("openApiGeneratorIgnoreFile")
}
/build/generated/sources/openapi/main/java/**
!build/generated/sources/openapi/main/java/org/**
Or like this for Kotlin:
val openApiGeneratorIgnoreFile = layout.projectDirectory.file(".openapi-generator-ignore")
openApiGenerate {
generatorName.set("kotlin")
outputDir.set(layout.buildDirectory.dir("generated/sources/openapi/main/kotlin").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)
packageName.set("org.sonatype.nexus.client")
apiPackage.set("org.sonatype.nexus.client.api")
modelPackage.set("org.sonatype.nexus.client.model")
configOptions.set(mapOf(
"sourceFolder" to "",
"enumPropertyNaming" to "original"
))
ignoreFileOverride.set(
openApiGeneratorIgnoreFile.asFile.absolutePath
)
}
// TODO: work-around for https://github.com/OpenAPITools/openapi-generator/issues/10214
tasks.openApiGenerate {
inputs
.files(openApiGeneratorIgnoreFile)
.withPathSensitivity(NONE)
.withPropertyName("openApiGeneratorIgnoreFile")
}
sourceSets {
main {
java {
srcDir(tasks.openApiGenerate)
}
}
}
/build/generated/sources/openapi/main/kotlin/**
!build/generated/sources/openapi/main/kotlin/org/**
Or like this for Kotlin:
val openApiGeneratorIgnoreFile = layout.projectDirectory.file(".openapi-generator-ignore") openApiGenerate { generatorName.set("kotlin") outputDir.set(layout.buildDirectory.dir("generated/sources/openapi/main/kotlin").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) packageName.set("org.sonatype.nexus.client") apiPackage.set("org.sonatype.nexus.client.api") modelPackage.set("org.sonatype.nexus.client.model") configOptions.set(mapOf( "sourceFolder" to "", "enumPropertyNaming" to "original" )) ignoreFileOverride.set( openApiGeneratorIgnoreFile.asFile.absolutePath ) } // TODO: @bkautler work-around for https://github.com/OpenAPITools/openapi-generator/issues/10214 tasks.openApiGenerate { inputs .files(openApiGeneratorIgnoreFile) .withPathSensitivity(NONE) .withPropertyName("openApiGeneratorIgnoreFile") } sourceSets { main { java { srcDir(tasks.openApiGenerate) } } }
/build/generated/sources/openapi/main/kotlin/** !build/generated/sources/openapi/main/kotlin/org/**
Thanks for your example, i hope it helps )
Description
Hello!
I'm trying to generate code via OpenAPI Generator Gradle Plugin version 5.1.1 I can't understand behavior of this plugin, it generates new gradle project, but not only kotlin classes
my task configuration is
As far as i know, maven plugin generates just classes, not new project Looks like gradle plugins works as generator cli
Why openapi generator gradle plugin generates new project?
openapi-generator version
5.1.1
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement