forked from loafle/openapi-generator-original
[Java] maven plugin to clean-up output before generation (#14935)
This commit is contained in:
parent
25adbe33a6
commit
18e28ab761
@ -67,6 +67,7 @@
|
||||
<apiPackage>remote.org.openapitools.client.api</apiPackage>
|
||||
<modelPackage>remote.org.openapitools.client.model</modelPackage>
|
||||
<invokerPackage>remote.org.openapitools.client</invokerPackage>
|
||||
<cleanupOutput>true</cleanupOutput>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@ -76,8 +77,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<proc>none</proc>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -26,6 +26,7 @@
|
||||
<configuration>
|
||||
<!-- specify the swagger yaml -->
|
||||
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
|
||||
<cleanupOutput>true</cleanupOutput>
|
||||
|
||||
<!-- target to generate kotlin client code -->
|
||||
<generatorName>kotlin</generatorName>
|
||||
|
@ -59,8 +59,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<proc>none</proc>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user