[BUG] Java gradle.properties
Description
When generating java client, it seem its not possible to use gradleProperties to set gradle.properties values.
tries with java.yaml config file, and directly as argument using CLI, nothing work
the generated gradle.properties is EMPTY.
using the openapi-generator-cli author template -g java -o ./templates/java and editing the gradle.properties templates, specifying this directory in my CLI command does not change anything
I'm actually using the npm library on a OSX environement
openapi-generator version
@openapitools/openapi-generator-cli : 2.19.1
OpenAPI declaration file content or url
generatorName: java
additionalProperties:
library: native
dateLibrary: java8-localdatetime
developerName: MyName
developerEmail: "[email protected]"
developerOrganization: MyCompany
developerOrganizationUrl: "https://MyCompany.fr"
annotationLibrary: "swagger2"
hideGenerationTimestamp: "true"
gradleProperties:
- "spotless_java_formatter=../format/eclipse-java-formatter-1.0.0.xml"
- "spotless_java_importorder=../format/eclipse-java-importorder-1.0.0.importorder"
- "spotless_gradle_formatter=../format/eclipse-groovy-formatter-1.0.0.properties"
Generation Details
using preview config file and a swagger.json i use:
openapi-generator-cli generate -i ./dist/swagger.json -g java -o dist/clients/petstore-core-sdk-client-java -c ./src/configs/java.yaml
Client is generated using most of the yaml settings, except gradleProperties which remain empty.
Steps to reproduce
- use the previous yaml, or use the
gradlePropertiesdirectly from the CLI - generate the client using, as example:
openapi-generator-cli generate -i ./dist/swagger.json -g java -o dist/clients/petstore-core-sdk-client-java -c ./src/configs/java.yaml - look for dist/clients/petstore-core-sdk-client-java/gradle.properties content
- it's empty, it must contain the
gradlePropertiesarray from the yaml, 1 item per line
Suggest a fix
I dont know how to fix it actually, but maybe it could be a nice idea to add it to the tests
what about using customized templates, e.g. -t via CLI?
Hi,
i tried, as said, but nothing:
openapi-generator-cli author template -g java -o ./templates/java
to get the original template, the gradle.properties file look like:
# This file is automatically generated by OpenAPI Generator (https://github.com/openAPITools/openapi-generator).
# To include other gradle properties as part of the code generation process, please use the `gradleProperties` option.
#
# Gradle properties reference: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
# For example, uncomment below to build for Android
#target = android
THIS IS MY OVERRIDE
{{#gradleProperties}}
{{{.}}}
{{/gradleProperties}}
then i used openapi-generator-cli generate -i ./dist/swagger.json -g java -o dist/clients/petstore-core-sdk-client-java -c ./src/configs/java.yaml -t ./templates/java
but gradle.properties still empty, no comments, no THIS IS MY OVERRIDE. it seem the file is created, but that's all.
ive made another simple test, removed my config file path from the cmd line, and the file was generated, i continue to make some tests to understand what's wrong
To include other gradle properties as part of the code generation process, please use the
gradlePropertiesoption.
according to the comment, looks like you can simply use the gradleProperties option directly without using customized templates
Hi, yeah i know, here is what i've found using my generation command like before, i can reproduce the problem:
additionalProperties:
library: native
dateLibrary: java8-localdatetime
developerName: MyCompany
developerEmail: "[email protected]"
developerOrganization: MyCompany
developerOrganizationUrl: "https://MyCompany.fr"
annotationLibrary: "swagger2"
hideGenerationTimestamp: "true"
gradleProperties: |
spotless_java_formatter=../format/eclipse-java-formatter-1.0.0.xml
spotless_java_importorder=../format/eclipse-java-importorder-1.0.0.importorder
spotless_gradle_formatter=../format/eclipse-groovy-formatter-1.0.0.properties
result is: client is generated, code is customized etc... but NO CONTENT in gradle.properties
BUT, when i use:
additionalProperties:
#library: native <-- note the commented library
dateLibrary: java8-localdatetime
developerName: MyCompany
developerEmail: "[email protected]"
developerOrganization: MyCompany
developerOrganizationUrl: "https://MyCompany.fr"
annotationLibrary: "swagger2"
hideGenerationTimestamp: "true"
gradleProperties: |
spotless_java_formatter=../format/eclipse-java-formatter-1.0.0.xml
spotless_java_importorder=../format/eclipse-java-importorder-1.0.0.importorder
spotless_gradle_formatter=../format/eclipse-groovy-formatter-1.0.0.properties
it's working as it should.
it seem that library properties make the template ignore gradle.properties, i'm going to investigate into that
edit: using library: restclient worked, so it seem that native library have a problem/ignoring this file template.
i dont know where i can find the rules used with this property
looks like https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/native/gradle.properties.mustache explains why
i'll try to file a PR to fix it later
thanks for reporting the issue and doing the tests
Yeah just found it too as i understand, if file is present in this directory, it will override the template, right ? i've made a commit
that's the "default" template
the template you provided should override it
and you will need to put it in the right folder under "libraries/native" in in order for native library to pick it up
I've made a PR https://github.com/OpenAPITools/openapi-generator/pull/21128
just merged. thanks for the contribution.