Skip to content

Commit 1734ac4

Browse files
dalbothekwing328
authored andcommitted
Add option to skip Maven plugin execution (swagger-api#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
1 parent fea8699 commit 1734ac4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

modules/swagger-codegen-maven-plugin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ mvn clean compile
5959
- `generateModelDocumentation` - generate the model documentation (`true` by default. Only available if `generateModels` is `true`)
6060
- `generateSupportingFiles` - generate the supporting files (`true` by default)
6161
- `supportingFilesToGenerate` - A comma separated list of supporting files to generate. All files is the default.
62+
- `skip` - skip code generation (`false` by default. Can also be set globally through the `codegen.skip` property)
6263

6364
### Custom Generator
6465

modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ public class CodeGenMojo extends AbstractMojo {
228228
@Parameter(name = "generateApiDocumentation", required = false)
229229
private Boolean generateApiDocumentation = true;
230230

231-
231+
/**
232+
* Skip the execution.
233+
*/
234+
@Parameter(name = "skip", property = "codegen.skip", required = false, defaultValue = "false")
235+
private Boolean skip;
232236

233237
/**
234238
* Add the output directory to the project as a source root, so that the
@@ -252,6 +256,14 @@ public class CodeGenMojo extends AbstractMojo {
252256
@Override
253257
public void execute() throws MojoExecutionException {
254258

259+
if(skip) {
260+
getLog().info("Code generation is skipped.");
261+
// Even when no new sources are generated, the existing ones should
262+
// still be compiled if needed.
263+
addCompileSourceRootIfConfigured();
264+
return;
265+
}
266+
255267
//attempt to read from config file
256268
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configurationFile);
257269

@@ -427,7 +439,11 @@ public void execute() throws MojoExecutionException {
427439
throw new MojoExecutionException("Code generation failed. See above for the full exception.");
428440
}
429441

430-
if (addCompileSourceRoot) {
442+
addCompileSourceRootIfConfigured();
443+
}
444+
445+
private void addCompileSourceRootIfConfigured() {
446+
if(addCompileSourceRoot) {
431447
final Object sourceFolderObject = configOptions == null ? null : configOptions.get(CodegenConstants.SOURCE_FOLDER);
432448
final String sourceFolder = sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
433449

0 commit comments

Comments
 (0)