You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Laurie C (Jira)" <ji...@apache.org> on 2022/10/11 04:37:00 UTC

[jira] [Commented] (SUREFIRE-2112) Surefire not using toolchain JDK during test execution

    [ https://issues.apache.org/jira/browse/SUREFIRE-2112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17615456#comment-17615456 ] 

Laurie C commented on SUREFIRE-2112:
------------------------------------

For the plugin to honour the toolchain, it must spawn a child process using that toolchain.

From my testing, the only circumstance in which surefire spawns a child process is if it's configured with `<forkCount>1</forkCount>` and without _any_ other parallelism configuration or option.  Specifically and for example, `1C` _always_ runs in the hosting maven process. 

Only then can the child process use the desired toolchain, and it's up to the junit runner inside that child process to do its own parallel execution (easy enough with junit 5, haven't figured out how to do it for junit 4).

This is using surefire plugin 3.0.0-M7.

> Surefire not using toolchain JDK during test execution
> ------------------------------------------------------
>
>                 Key: SUREFIRE-2112
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-2112
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: Maven Surefire Plugin
>    Affects Versions: 3.0.0-M7
>         Environment: Ubuntu 22.04
>            Reporter: Ruan de Bruyn
>            Priority: Minor
>         Attachments: surefire-bug-1.zip
>
>
> I am running an Ubuntu system, with several JDKs installed, but the "default" one is JDK11 (i.e output of {{java -version}} in a shell is openjdk 11). I have all of my installed JDKs defined in my toolchains.xml in my local .m2 folder. In a Java 17 Spring Boot project, when I try to run {{mvn clean install}} and specify the usage of JDK17 using the toolchains plugin, it compiles all source and test classes, but does not run the tests. The error:
> {{...has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0}}
> It seems like surefire compiles the test code with JDK17, but tries to execute them with my system's JDK11. If I skip the tests with {{mvn clean install -DskipTests}} the build passes, and I see the compiled test classes. If I hardcode my JDK17 location in the surefire plugin entry in the pom.xml, I can get the build to pass:
> {{<plugin>}}
> {{    <groupId>org.apache.maven.plugins</groupId>}}
> {{    <artifactId>maven-surefire-plugin</artifactId>}}
> {{    <version>3.0.0-M7</version>}}
> {{    <configuration>}}
> {{        <jvm>/usr/lib/jvm/java-17-openjdk-amd64/bin/java</jvm>}}
> {{    </configuration>}}
> {{</plugin>}}
> However, I would expect surefire-plugin to be aware of the Java 17 toolchain I'm using, and execute the tests with JDK17, without having to specify the correct JDK to use for test execution. I've attached a simple project that recreates the issue, as well as a copy of my toolchains.xml file



--
This message was sent by Atlassian Jira
(v8.20.10#820010)