diff --git a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AbstractMicronautAotCliMojo.java b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AbstractMicronautAotCliMojo.java index ceb43d41e..baeec85db 100644 --- a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AbstractMicronautAotCliMojo.java +++ b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AbstractMicronautAotCliMojo.java @@ -15,14 +15,18 @@ */ package io.micronaut.maven.aot; +import io.micronaut.maven.MojoUtils; import io.micronaut.maven.services.CompilerService; import io.micronaut.maven.services.DependencyResolutionService; import io.micronaut.maven.services.ExecutorService; + +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.invoker.InvocationResult; import org.apache.maven.shared.invoker.MavenInvocationException; +import org.apache.maven.toolchain.ToolchainManager; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.eclipse.aether.artifact.Artifact; @@ -74,6 +78,10 @@ public abstract class AbstractMicronautAotCliMojo extends AbstractMicronautAotMo private final ExecutorService executorService; private final DependencyResolutionService dependencyResolutionService; + + private final MavenSession mavenSession; + + private final ToolchainManager toolchainManager; @Parameter private List aotDependencies; @@ -88,10 +96,13 @@ public abstract class AbstractMicronautAotCliMojo extends AbstractMicronautAotMo @Inject public AbstractMicronautAotCliMojo(CompilerService compilerService, ExecutorService executorService, - MavenProject mavenProject, DependencyResolutionService dependencyResolutionService) { + MavenProject mavenProject, DependencyResolutionService dependencyResolutionService, + MavenSession mavenSession, ToolchainManager toolchainManager) { super(compilerService, mavenProject); this.executorService = executorService; this.dependencyResolutionService = dependencyResolutionService; + this.mavenSession = mavenSession; + this.toolchainManager = toolchainManager; } protected abstract List getExtraArgs() throws MojoExecutionException; @@ -161,8 +172,11 @@ private Xpp3Dom createExecPluginConfig() throws DependencyResolutionException, M MojoExecutor.Element[] runnerArgs = Stream.concat(Stream.concat(jvmArgs, mainArgs), getExtraArgs().stream()) .map(arg -> element("argument", arg)) .toArray(MojoExecutor.Element[]::new); + + String javaExecutable = MojoUtils.findJavaExecutable(toolchainManager, mavenSession); + return configuration( - element("executable", "java"), + element("executable", javaExecutable), element("arguments", runnerArgs) ); } diff --git a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AotAnalysisMojo.java b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AotAnalysisMojo.java index 0ae10ff70..09f313d23 100644 --- a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AotAnalysisMojo.java +++ b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AotAnalysisMojo.java @@ -21,11 +21,13 @@ import io.micronaut.maven.services.DependencyResolutionService; import io.micronaut.maven.services.ExecutorService; import org.apache.commons.io.FileUtils; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; +import org.apache.maven.toolchain.ToolchainManager; import javax.inject.Inject; import java.io.File; @@ -73,8 +75,9 @@ public class AotAnalysisMojo extends AbstractMicronautAotCliMojo { @Inject @SuppressWarnings("CdiInjectionPointsInspection") public AotAnalysisMojo(CompilerService compilerService, ExecutorService executorService, MavenProject mavenProject, - DependencyResolutionService dependencyResolutionService) { - super(compilerService, executorService, mavenProject, dependencyResolutionService); + DependencyResolutionService dependencyResolutionService, + MavenSession mavenSession, ToolchainManager toolchainManager) { + super(compilerService, executorService, mavenProject, dependencyResolutionService, mavenSession, toolchainManager); } @Override diff --git a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AotSampleMojo.java b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AotSampleMojo.java index 28f53b66d..7cce8c4a4 100644 --- a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AotSampleMojo.java +++ b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/aot/AotSampleMojo.java @@ -18,10 +18,13 @@ import io.micronaut.maven.services.CompilerService; import io.micronaut.maven.services.DependencyResolutionService; import io.micronaut.maven.services.ExecutorService; + +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; +import org.apache.maven.toolchain.ToolchainManager; import javax.inject.Inject; import java.io.File; @@ -39,8 +42,9 @@ public class AotSampleMojo extends AbstractMicronautAotCliMojo { @Inject public AotSampleMojo(CompilerService compilerService, ExecutorService executorService, MavenProject mavenProject, - DependencyResolutionService dependencyResolutionService) { - super(compilerService, executorService, mavenProject, dependencyResolutionService); + DependencyResolutionService dependencyResolutionService, + MavenSession mavenSession, ToolchainManager toolchainManager) { + super(compilerService, executorService, mavenProject, dependencyResolutionService, mavenSession, toolchainManager); } @Override