Ensure that quarkus:dev works with yet to be compiled Kotlin project

Fixes: #6931
This commit is contained in:
Georgios Andrianakis
2020-02-03 10:01:50 +02:00
parent b9c974923d
commit 79f169aae5

View File

@@ -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<Path, Long> readPomFileTimestamps(DevModeRunner runner) throws IOException {
Map<Path, Long> ret = new HashMap<>();
for (Path i : runner.getPomFiles()) {