Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/main/java/org/springdoc/maven/plugin/SpringDocMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Map;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -80,6 +81,12 @@ public class SpringDocMojo extends AbstractMojo {
@Parameter(defaultValue = "false", property = "springdoc.skip")
private boolean skip;

/**
* Fail build on error, if set to true. Default is false.
*/
@Parameter(defaultValue = "false", property = "springdoc.failOnError")
private boolean failOnError;

/**
* Headers to send in request
*/
Expand All @@ -97,7 +104,7 @@ public class SpringDocMojo extends AbstractMojo {
*/
private static final String GET = "GET";

public void execute() {
public void execute() throws MojoFailureException {
if (skip) {
getLog().info("Skip execution as per configuration");
return;
Expand All @@ -114,10 +121,18 @@ public void execute() {
Files.write(Paths.get(outputDir.getAbsolutePath() + "/" + outputFileName), result.getBytes(StandardCharsets.UTF_8));
if (attachArtifact) addArtifactToMaven();
} else {
getLog().error("An error has occurred: Response code " + responseCode);
String message = "An error has occurred, response code: " + responseCode;
if(failOnError) {
throw new MojoFailureException(message);
} else {
getLog().error(message);
}
}
} catch (Exception e) {
getLog().error("An error has occurred", e);
if(failOnError) {
throw new MojoFailureException("An error has occurred: " + e.getMessage());
}
}
}

Expand Down