diff --git a/modules/openapi-generator-maven-plugin/README.md b/modules/openapi-generator-maven-plugin/README.md
index 898bf6652cab..d3d6a8859da7 100644
--- a/modules/openapi-generator-maven-plugin/README.md
+++ b/modules/openapi-generator-maven-plugin/README.md
@@ -98,7 +98,8 @@ mvn clean compile
| `skipIfSpecIsUnchanged` | `codegen.skipIfSpecIsUnchanged` | Skip the execution if the source file is older than the output folder (`false` by default. Can also be set globally through the `codegen.skipIfSpecIsUnchanged` property)
| `addCompileSourceRoot` | `openapi.generator.maven.plugin.addCompileSourceRoot` | Add the output directory to the project as a source root, so that the generated java types are compiled and included in the project artifact (`true` by default). Mutually exclusive with `addTestCompileSourceRoot`.
| `addTestCompileSourceRoot` | `openapi.generator.maven.plugin.addTestCompileSourceRoot` | Add the output directory to the project as a test source root, so that the generated java types are compiled only for the test classpath of the project (`false` by default). Mutually exclusive with `addCompileSourceRoot`.
-| `environmentVariables` | N/A | A **map** of items conceptually similar to "environment variables" or "system properties". These are merged into a map of global settings available to all aspects of the generation flow. Use this map for any options documented elsewhere as `systemProperties`.
+| `environmentVariables` | N/A | deprecated. Use globalProperties instead.
+| `globalProperties` | N/A | A **map** of items conceptually similar to "environment variables" or "system properties". These are available to all aspects of the generation flow. See [Global Properties](https://openapi-generator.tech/docs/globals/) for list of available properties.
| `configHelp` | `codegen.configHelp` | dumps the configuration help for the specified library (generates no sources)
### Configuring **map** structures
@@ -114,17 +115,17 @@ For configuration options documented as a **map** above, the key/value options m
```
This configuration node location will match that of the plugin configuration examples at the top of this document and in the section below. Here, `option` matches in option name in the first column in the table from the previous section.
-The `key` and `value` text are any values you'd like to provide for that option. As an example, to configure `environmentVariables` to match the `-Dmodels=User,Pet` example from our [Selective Generation](https://openapi-generator.tech/docs/customization#selective-generation) documentation, see below.
+The `key` and `value` text are any values you'd like to provide for that option. As an example, to configure `globalProperties` to match the `--global-property models=User,Pet` example from our [Selective Generation](https://openapi-generator.tech/docs/customization#selective-generation) documentation, see below.
```xml
-
+
User,Pet
-
+
```
-Not that some of these environment variable options may overwrite or conflict with other options available to the maven plugin. For example, the above `environmentVariables` example is equivalent to the following:
+Not that some of these environment variable options may overwrite or conflict with other options available to the maven plugin. For example, the above `globalProperties` example is equivalent to the following:
```xml
@@ -133,7 +134,7 @@ Not that some of these environment variable options may overwrite or conflict wi
```
-The difference here is that you may define `generateModels` and `modelsToGenerate` as properties, while `environmentVariables` may only be configured as a configuration node.
+The difference here is that you may define `generateModels` and `modelsToGenerate` as properties, while `globalProperties` may only be configured as a configuration node.
### Custom Generator
diff --git a/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java b/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java
index 628c15390c94..80639e97ff00 100644
--- a/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java
+++ b/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java
@@ -407,12 +407,12 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(defaultValue = "false", property = "openapi.generator.maven.plugin.addTestCompileSourceRoot")
private boolean addTestCompileSourceRoot = false;
- // TODO: Rename to global properties in version 5.0
+ // TODO: Rename to global properties in version 5.1
@Parameter
protected Map environmentVariables = new HashMap<>();
@Parameter
- protected Map originalEnvironmentVariables = new HashMap<>();
+ protected Map globalProperties = new HashMap<>();
@Parameter(property = "codegen.configHelp")
private boolean configHelp = false;
@@ -430,7 +430,6 @@ public void setBuildContext(BuildContext buildContext) {
@Override
public void execute() throws MojoExecutionException {
File inputSpecFile = new File(inputSpec);
- resetEnvironmentVariables();
addCompileSourceRootIfConfigured();
try {
@@ -699,13 +698,19 @@ public void execute() throws MojoExecutionException {
applyReservedWordsMappingsKvpList(reservedWordsMappings, configurator);
}
- if (environmentVariables != null) {
- for (String key : environmentVariables.keySet()) {
- originalEnvironmentVariables.put(key, GlobalSettings.getProperty(key));
- String value = environmentVariables.get(key);
- if (value != null) {
- configurator.addGlobalProperty(key, value);
- }
+ if (globalProperties == null) {
+ globalProperties = new HashMap<>();
+ }
+
+ if (environmentVariables != null && environmentVariables.size() > 0) {
+ globalProperties.putAll(environmentVariables);
+ getLog().warn("environmentVariables is deprecated and will be removed in version 5.1. Use globalProperties instead.");
+ }
+
+ for (String key : globalProperties.keySet()) {
+ String value = globalProperties.get(key);
+ if (value != null) {
+ configurator.addGlobalProperty(key, value);
}
}
@@ -857,19 +862,6 @@ private void addCompileSourceRootIfConfigured() throws MojoExecutionException {
}
}
- private void resetEnvironmentVariables() {
- // Reset all environment variables to their original value. This prevents unexpected
- // behaviour
- // when running the plugin multiple consecutive times with different configurations.
- for (Map.Entry entry : originalEnvironmentVariables.entrySet()) {
- if (entry.getValue() == null) {
- GlobalSettings.clearProperty(entry.getKey());
- } else {
- GlobalSettings.setProperty(entry.getKey(), entry.getValue());
- }
- }
- }
-
/**
* This method enables conversion of true/false strings in
* config.additionalProperties (configuration/configOptions) to proper booleans.