Skip to content

Commit 0c75e97

Browse files
committed
Use same JVM that maven is using.
1 parent 25dd92d commit 0c75e97

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,21 @@
22

33
import org.apache.maven.artifact.DependencyResolutionRequiredException;
44
import org.apache.maven.plugin.AbstractMojo;
5-
import org.apache.maven.plugin.MojoExecutionException;
65
import org.apache.maven.plugin.MojoFailureException;
76
import org.apache.maven.project.MavenProject;
8-
import org.codehaus.plexus.util.cli.CommandLineException;
9-
import org.codehaus.plexus.util.cli.CommandLineTimeOutException;
10-
import org.codehaus.plexus.util.cli.CommandLineUtils;
11-
import org.codehaus.plexus.util.cli.Commandline;
12-
import org.codehaus.plexus.util.cli.StreamConsumer;
7+
import org.codehaus.plexus.util.cli.*;
138

14-
import static org.scalatest.tools.maven.MojoUtils.*;
15-
16-
import java.io.*;
17-
import java.util.Arrays;
18-
import java.util.Collections;
19-
import java.util.List;
20-
import java.util.ArrayList;
21-
import java.util.Map;
22-
23-
import static java.util.Collections.singletonList;
24-
25-
import java.net.MalformedURLException;
26-
import java.net.URLClassLoader;
27-
import java.net.URL;
9+
import java.io.File;
2810
import java.lang.reflect.InvocationTargetException;
2911
import java.lang.reflect.Method;
12+
import java.net.MalformedURLException;
13+
import java.net.URL;
14+
import java.net.URLClassLoader;
15+
import java.util.*;
16+
17+
import static java.util.Collections.singletonList;
18+
import static org.apache.commons.lang3.StringUtils.isEmpty;
19+
import static org.scalatest.tools.maven.MojoUtils.*;
3020

3121
/**
3222
* Provides the base for all mojos.
@@ -270,7 +260,7 @@ private boolean runForkingOnce(String[] args) throws MojoFailureException {
270260

271261
final Commandline cli = new Commandline();
272262
cli.setWorkingDirectory(project.getBasedir());
273-
cli.setExecutable("java");
263+
cli.setExecutable(getJvm());
274264

275265
// Set up environment
276266
if (environmentVariables != null) {
@@ -329,6 +319,19 @@ public void consumeLine(final String line) {
329319
}
330320
}
331321

322+
private String getJvm()
323+
{
324+
// use the same JVM as the one used to run Maven (the "java.home" one)
325+
String jvmToUse = System.getProperty( "java.home" ) + File.separator + "bin" + File.separator + "java";
326+
327+
if (isEmpty(jvmToUse)) {
328+
jvmToUse = "java";
329+
}
330+
331+
getLog().debug( "Using JVM: " + jvmToUse );
332+
return jvmToUse;
333+
}
334+
332335
private String buildClassPathEnvironment() {
333336
StringBuffer buf = new StringBuffer();
334337
boolean first = true;

0 commit comments

Comments
 (0)