-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][Gradle plugin] templateDir can't refer to a classpath anymore #14455
Comments
@SardarNL thanks for reporting the issue. cc @erichaagdev |
Thanks for reporting this! This is not a bug. I do not believe the suggested fix of removing the Using files from the file system, dependencies, or archives in Gradle tasks is very common. The typical way to accomplish this is to actually split the work being done into two tasks. In the context of the OpenAPI Generator Gradle plugin, the first task is a def templateDir = layout.buildDirectory.dir('templates/openapi')
def copyOpenApiTask = tasks.register("copyOpenApi", Copy) {
from '/absolute/path/to/project/path/to/templates'
into templateDir
}
tasks.register("generateOpenApi", org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
// ...
dependsOn copyOpenApiTask
templateDir = templateDir.get().asFile.path
} |
Looks like copying from Copying on every build touches all template files. I wonder if this fact messes up with |
Yes, unfortunately a few more steps will be required. In general you will have to:
From here, the rest of the configuration is the same as my previous comment.
This is part of the reason why it is recommended to split the copying and generation to two tasks. |
Thanks! |
My pleasure! If you still have questions or want help on the implementation, please consider joining the openapi-generator Slack. Or, as this issue is more related to Gradle, the Gradle Community Slack. |
Description
templateDir
could be assigneda/path/to/directory
which will be looked up in different places, includingclasspath
set viabuildsript
:This feature made it possible to provide templates in a .jar dependency instead of keeping it with the project source code. After all, there many many services and just one custom
x-my-feature
implementation used in OpenAPI spec yaml.The latest change added
@PathSensitive(PathSensitivity.RELATIVE)
totemplateDir
property which forces lookup in the current directory relative tobuild.gradle
file.With that change, it became impossible to refer to templates in the
classpath
. Is there a way to specify templates from the classpath explicitly (classpath:
prefix doesn't work)? Or maybe is there a way to revert that change as it was vastly superior before.latest
org.openapi.generator
Gradle plugin version which works 6.2.0first
org.openapi.generator
version which doesn't work 6.2.1 (latest)gradle version 7.4.x to 7.6 - in all of them this issue happens
Generation Details
Note that
path/to/templates
does exist on the classpath, but gradle plugin looks for a relative path tobuild.gradle
only. So it looks in the project code (user ofx-my-feature
) and doesn't look for templates in buildscript classpath where necessary templates were provided as a dependency. This setup did work perfectly before.Steps to reproduce
Create a
.jar
with your custom templates. Add them tobuildscript/dependencies/classpath
. Configure the generator withtemplateDir = path/to/templates/in/jar
. The generator will fail with a complaint that directory doesn't exist.Related issues/PRs
I believe this pull request introduced the regression.
Suggest a fix
Don't annotate
templateDir
withPathSensitivity
?The text was updated successfully, but these errors were encountered: