From 79f169aae5a23b7a4402f88622aeb0ebea6d3961 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 3 Feb 2020 10:01:50 +0200 Subject: [PATCH] Ensure that quarkus:dev works with yet to be compiled Kotlin project Fixes: #6931 --- .../main/java/io/quarkus/maven/DevMojo.java | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) 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 ceef1c3df..68241025a 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -100,6 +100,9 @@ public class DevMojo extends AbstractMojo { private static final String ORG_APACHE_MAVEN_PLUGINS = "org.apache.maven.plugins"; private static final String MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin"; + private static final String ORG_JETBRAINS_KOTLIN = "org.jetbrains.kotlin"; + private static final String KOTLIN_MAVEN_PLUGIN = "kotlin-maven-plugin"; + /** * The directory for compiled classes. */ @@ -260,27 +263,19 @@ public class DevMojo extends AbstractMojo { //if the user did not compile we run it for them if (compileNeeded) { - // Compile the project - final String key = ORG_APACHE_MAVEN_PLUGINS + ":" + MAVEN_COMPILER_PLUGIN; - final Plugin plugin = project.getPlugin(key); - if (plugin == null) { - throw new MojoExecutionException("Failed to locate " + key + " among the project plugins"); + // compile the Kotlin sources if needed + final String kotlinMavenPluginKey = ORG_JETBRAINS_KOTLIN + ":" + KOTLIN_MAVEN_PLUGIN; + final Plugin kotlinMavenPlugin = project.getPlugin(kotlinMavenPluginKey); + if (kotlinMavenPlugin != null) { + executeCompileGoal(kotlinMavenPlugin, ORG_JETBRAINS_KOTLIN, KOTLIN_MAVEN_PLUGIN); } - Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); - if (configuration == null) { - configuration = MojoExecutor.configuration(); + + // Compile the Java sources if needed + final String compilerPluginKey = ORG_APACHE_MAVEN_PLUGINS + ":" + MAVEN_COMPILER_PLUGIN; + final Plugin compilerPlugin = project.getPlugin(compilerPluginKey); + if (compilerPlugin != null) { + executeCompileGoal(compilerPlugin, ORG_APACHE_MAVEN_PLUGINS, MAVEN_COMPILER_PLUGIN); } - MojoExecutor.executeMojo( - MojoExecutor.plugin( - MojoExecutor.groupId(ORG_APACHE_MAVEN_PLUGINS), - MojoExecutor.artifactId(MAVEN_COMPILER_PLUGIN), - MojoExecutor.version(plugin.getVersion())), - MojoExecutor.goal("compile"), - configuration, - MojoExecutor.executionEnvironment( - project, - session, - pluginManager)); } try { @@ -366,6 +361,25 @@ public class DevMojo extends AbstractMojo { } } + private void executeCompileGoal(Plugin plugin, String groupId, String artifactId) throws MojoExecutionException { + Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); + if (configuration == null) { + configuration = MojoExecutor.configuration(); + } + MojoExecutor.executeMojo( + MojoExecutor.plugin( + MojoExecutor.groupId(groupId), + MojoExecutor.artifactId(artifactId), + MojoExecutor.version(plugin.getVersion()), + plugin.getDependencies()), + MojoExecutor.goal("compile"), + configuration, + MojoExecutor.executionEnvironment( + project, + session, + pluginManager)); + } + private Map readPomFileTimestamps(DevModeRunner runner) throws IOException { Map ret = new HashMap<>(); for (Path i : runner.getPomFiles()) {