From ef19daac561c2fb288857a4eb249c4f92ca1b56c Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Fri, 29 Nov 2019 09:07:32 +1100 Subject: [PATCH] Check if the user ran compile and otherwise run it for them Fixes #5832 --- .../main/java/io/quarkus/maven/DevMojo.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java index 2aa5acca4ae0c..f915e64dd7242 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -71,6 +71,30 @@ */ @Mojo(name = "dev", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) public class DevMojo extends AbstractMojo { + + /** + * running any one of these phases means the compile phase will have been run, if these have + * not been run we manually run compile + */ + private static final Set POST_COMPILE_PHASES = new HashSet<>(Arrays.asList( + "compile", + "process-classes", + "generate-test-sources", + "process-test-sources", + "generate-test-resources", + "process-test-resources", + "test-compile", + "process-test-classes", + "test", + "prepare-package", + "package", + "pre-integration-test", + "integration-test", + "post-integration-test", + "verify", + "install", + "deploy")); + /** * The directory for compiled classes. */ @@ -224,8 +248,20 @@ public void execute() throws MojoFailureException, MojoExecutionException { if (!sourceDir.isDirectory()) { getLog().warn("The project's sources directory does not exist " + sourceDir); } + //we check to see if there was a compile (or later) goal before this plugin + boolean compileNeeded = true; + for (String goal : session.getGoals()) { + if (POST_COMPILE_PHASES.contains(goal)) { + compileNeeded = false; + break; + } + if (goal.endsWith("quarkus:dev")) { + break; + } + } - if (!buildDir.isDirectory() || !new File(buildDir, "classes").isDirectory()) { + //if the user did not compile we run it for them + if (compileNeeded) { try { InvocationRequest request = new DefaultInvocationRequest(); request.setBatchMode(true);