diff --git a/modules/openapi-generator-maven-plugin/examples/java-client.xml b/modules/openapi-generator-maven-plugin/examples/java-client.xml
index 0161bd026ea..c08e9f54908 100644
--- a/modules/openapi-generator-maven-plugin/examples/java-client.xml
+++ b/modules/openapi-generator-maven-plugin/examples/java-client.xml
@@ -67,6 +67,7 @@
remote.org.openapitools.client.api
remote.org.openapitools.client.model
remote.org.openapitools.client
+ true
@@ -76,8 +77,8 @@
maven-compiler-plugin
3.8.1
- 1.7
- 1.7
+ 1.8
+ 1.8
none
diff --git a/modules/openapi-generator-maven-plugin/examples/kotlin.xml b/modules/openapi-generator-maven-plugin/examples/kotlin.xml
index 34b94a80f20..e084401a9ec 100644
--- a/modules/openapi-generator-maven-plugin/examples/kotlin.xml
+++ b/modules/openapi-generator-maven-plugin/examples/kotlin.xml
@@ -26,6 +26,7 @@
${project.basedir}/swagger.yaml
+ true
kotlin
diff --git a/modules/openapi-generator-maven-plugin/examples/multi-module/java-client/pom.xml b/modules/openapi-generator-maven-plugin/examples/multi-module/java-client/pom.xml
index 112163677f9..646168963fb 100644
--- a/modules/openapi-generator-maven-plugin/examples/multi-module/java-client/pom.xml
+++ b/modules/openapi-generator-maven-plugin/examples/multi-module/java-client/pom.xml
@@ -59,8 +59,8 @@
maven-compiler-plugin
3.8.1
- 1.7
- 1.7
+ 1.8
+ 1.8
none
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 48f2d6ee07d..a7780239b2c 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
@@ -41,6 +41,7 @@ import java.util.Set;
import com.google.common.io.ByteSource;
import com.google.common.io.CharSource;
import io.swagger.v3.parser.util.ClasspathHelper;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
@@ -99,6 +100,9 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(name = "output", property = "openapi.generator.maven.plugin.output")
private File output;
+ @Parameter(name = "cleanupOutput", property = "openapi.generator.maven.plugin.cleanupOutput", defaultValue = "false")
+ private boolean cleanupOutput;
+
/**
* Location of the OpenAPI spec, as URL or file.
*/
@@ -494,6 +498,16 @@ public class CodeGenMojo extends AbstractMojo {
LifecyclePhase.GENERATE_TEST_SOURCES.id().equals(mojo.getLifecyclePhase()) ?
"generated-test-sources/openapi" : "generated-sources/openapi");
}
+
+ if (cleanupOutput) {
+ try {
+ FileUtils.deleteDirectory(output);
+ LOGGER.info("Previous run output is removed from {}", output);
+ } catch (IOException e) {
+ LOGGER.warn("Failed to clean-up output directory {}", output, e);
+ }
+ }
+
addCompileSourceRootIfConfigured();
try {