forked from loafle/openapi-generator-original
Add option to skip Maven plugin execution (#5337)
* Add option to skip Maven plugin execution The execution is skipped if either the codegen.skip property or the <skip> configuration parameter is set. This is consistent with how many other Maven plugins, such as maven-exec-plugin and maven-clean-plugin, handle this. * Add documentation for Maven `skip` property
This commit is contained in:
@@ -59,6 +59,7 @@ mvn clean compile
|
||||
- `generateModelDocumentation` - generate the model documentation (`true` by default. Only available if `generateModels` is `true`)
|
||||
- `generateSupportingFiles` - generate the supporting files (`true` by default)
|
||||
- `supportingFilesToGenerate` - A comma separated list of supporting files to generate. All files is the default.
|
||||
- `skip` - skip code generation (`false` by default. Can also be set globally through the `codegen.skip` property)
|
||||
|
||||
### Custom Generator
|
||||
|
||||
|
||||
@@ -228,7 +228,11 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Parameter(name = "generateApiDocumentation", required = false)
|
||||
private Boolean generateApiDocumentation = true;
|
||||
|
||||
|
||||
/**
|
||||
* Skip the execution.
|
||||
*/
|
||||
@Parameter(name = "skip", property = "codegen.skip", required = false, defaultValue = "false")
|
||||
private Boolean skip;
|
||||
|
||||
/**
|
||||
* Add the output directory to the project as a source root, so that the
|
||||
@@ -252,6 +256,14 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException {
|
||||
|
||||
if(skip) {
|
||||
getLog().info("Code generation is skipped.");
|
||||
// Even when no new sources are generated, the existing ones should
|
||||
// still be compiled if needed.
|
||||
addCompileSourceRootIfConfigured();
|
||||
return;
|
||||
}
|
||||
|
||||
//attempt to read from config file
|
||||
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configurationFile);
|
||||
|
||||
@@ -427,7 +439,11 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
throw new MojoExecutionException("Code generation failed. See above for the full exception.");
|
||||
}
|
||||
|
||||
if (addCompileSourceRoot) {
|
||||
addCompileSourceRootIfConfigured();
|
||||
}
|
||||
|
||||
private void addCompileSourceRootIfConfigured() {
|
||||
if(addCompileSourceRoot) {
|
||||
final Object sourceFolderObject = configOptions == null ? null : configOptions.get(CodegenConstants.SOURCE_FOLDER);
|
||||
final String sourceFolder = sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user