diff --git a/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle b/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle index e9a5bb42e0ea..e5cde4680324 100644 --- a/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle +++ b/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle @@ -41,6 +41,9 @@ openApiGenerate { configOptions = [ dateLibrary: "java8" ] + systemProperties = [ + modelDocs: "false" + ] } task buildGoSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){ 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 db901f021c76..7c6ecd099da6 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 @@ -323,7 +323,7 @@ open class GenerateTask : DefaultTask() { @get:Internal val configOptions = project.objects.property>() - private val originalEnvironmentVariables = mutableMapOf() + private val originalEnvironmentVariables = mutableMapOf() private fun Property.ifNotEmpty(block: Property.(T) -> Unit) { if (isPresent) { @@ -352,8 +352,9 @@ open class GenerateTask : DefaultTask() { try { if (systemProperties.isPresent) { systemProperties.get().forEach { (key, value) -> - originalEnvironmentVariables[key] = System.getProperty(key) - System.setProperty(key, value) + // System.setProperty returns the original value for a key, or null. + // Cache the original value or null…we will late put the properties back in their original state. + originalEnvironmentVariables[key] = System.setProperty(key, value) configurator.addSystemProperty(key, value) } } @@ -540,8 +541,12 @@ open class GenerateTask : DefaultTask() { throw GradleException("Code generation failed.", e) } } finally { - originalEnvironmentVariables.forEach { entry -> - System.setProperty(entry.key, entry.value) + // Reset all modified system properties back to their original state + originalEnvironmentVariables.forEach { + when { + it.value == null -> System.clearProperty(it.key) + else -> System.setProperty(it.key, it.value) + } } originalEnvironmentVariables.clear() }