Skip to content

Commit

Permalink
Fix #6260 - make plugin thread safe by preventing parallelism. This n…
Browse files Browse the repository at this point in the history
…aive approach should be replaced in the future and allow parallel runs to achieve faster build times but this change will at least allow users to run maven with threads and other plugins and modules will run in parallel. This approach is also suggested by Apache Maven as a workaround: https://cwiki.apache.org/confluence/display/MAVEN/Parallel+builds+in+Maven+3
  • Loading branch information
MosheElisha committed Jun 19, 2020
1 parent 75a4426 commit 9595adc
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
/**
* Goal which generates client/server code from a swagger json/yaml definition.
*/
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
public class CodeGenMojo extends AbstractMojo {

@Parameter(name = "verbose", required = false, defaultValue = "false")
Expand Down Expand Up @@ -315,6 +315,13 @@ public class CodeGenMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException {
// Using the naive approach for achieving thread safety
synchronized (CodeGenMojo.class) {
execute_();
}
}

protected void execute_() throws MojoExecutionException {

if (skip) {
getLog().info("Code generation is skipped.");
Expand Down

0 comments on commit 9595adc

Please sign in to comment.