From 329843bc92897c5738efb4d0c5f8da62ac8c440b Mon Sep 17 00:00:00 2001 From: Kevin Howell Date: Thu, 21 Feb 2019 18:18:47 -0500 Subject: [PATCH] Gradle - make GenerateTask properties optional (#2185) This allows easier creation of custom `GenerateTask`. Specifically, this makes: - generateModelTests - generateModelDocumentation - generateApiTests - generateApiDocumentation - withXml optional, following the same pattern as other properties in GenerateTask. Without this change, we get `java.lang.IllegalStateException: No value has been specified for this provider.` until these properties are specified for the task, when attempting to define a custom generate task (such as one to generate API docs). --- .../gradle/plugin/tasks/GenerateTask.kt | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt index 1b07092bec5..f7eafc626e9 100644 --- a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt +++ b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt @@ -403,11 +403,25 @@ open class GenerateTask : DefaultTask() { GeneratorProperties.clearProperty(CodegenConstants.APIS) } - GeneratorProperties.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.get().toString()) - GeneratorProperties.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.get().toString()) - GeneratorProperties.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.get().toString()) - GeneratorProperties.setProperty(CodegenConstants.API_TESTS, generateApiTests.get().toString()) - GeneratorProperties.setProperty(CodegenConstants.WITH_XML, withXml.get().toString()) + if (generateApiDocumentation.isPresent) { + GeneratorProperties.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.get().toString()) + } + + if (generateModelDocumentation.isPresent) { + GeneratorProperties.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.get().toString()) + } + + if (generateModelTests.isPresent) { + GeneratorProperties.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.get().toString()) + } + + if (generateApiTests.isPresent) { + GeneratorProperties.setProperty(CodegenConstants.API_TESTS, generateApiTests.get().toString()) + } + + if (withXml.isPresent) { + GeneratorProperties.setProperty(CodegenConstants.WITH_XML, withXml.get().toString()) + } // now override with any specified parameters verbose.ifNotEmpty { value ->