Skip to content

Forked process don't respect JAVA_HOME when calling java #26

@DaniRey

Description

@DaniRey

With forkMode set to once or always new processes are forked to execute the tests. They start java using the command java, but in the maven ecosystem one would expect the forked processes to use $JAVA_HOME/bin/java instead. This would ensure that the same java version is used as for the build as for the test execution.

You can see the following line in your maven output when run with -X option (values in ??? are replaced with what they represent)
[14:07:24][???groupdId:artifactId???] [DEBUG] Forking ScalaTest via: /bin/sh -c cd ???basedir??? && java -Dbasedir=???basedir??? org.scalatest.tools.Runner -R '???basedir???/target/classes ???basedir???/target/test-classes' -o -u ???basedir???/target/surefire-reports/

but would expect the following

[14:07:24][???groupdId:artifactId???] [DEBUG] Forking ScalaTest via: /bin/sh -c cd ???basedir??? && $JAVA_HOME/bin/java -Dbasedir=???basedir??? org.scalatest.tools.Runner -R '???basedir???/target/classes ???basedir???/target/test-classes' -o -u ???basedir???/target/surefire-reports/

A typical symptom of this is the following error message:
Unsupported major.minor version 52.0

This happens if your java code is compiled with Java 8 and then executed with Java <8. Other combinations of Java versions will lead to slightly different error messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions