You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Nils Breunese <ni...@breun.nl> on 2025/01/03 13:47:10 UTC

Surefire plugin doesn't use toolchain JDK for forked tests?

Hello,

I’m currently exploring adopting the Maven Toolchains Plugin (https://maven.apache.org/plugins/maven-toolchains-plugin/select-jdk-toolchain-mojo.html), but it seems that when using forked tests with the Maven Surefire Plugin (forkCount: 1, reuseForks: false) not the toolchain JDK is forked, but the JDK used to start Maven. This is causing my forked tests to fail, because the toolchain JDK is version 21 and the JDK running Maven is 17, so the forked JDK (17) cannot run the test which is compiled with the toolchain JDK (21). I would have expected the JDK for the forked tests to also be the toolchain JDK (21) in this scenario.

Is what I’m seeing expected behavior and is there something I can do have it use the toolchain JDK for the forked tests, or is this a bug and should I create a ticket for this?

Thanks, Nils.

Re: Surefire plugin doesn't use toolchain JDK for forked tests?

Posted by Nils Breunese <ni...@breun.nl>.
I guess this was already been reported as https://issues.apache.org/jira/browse/SUREFIRE-1942 (fork ignores toolchain higher than system) in 2021?

Nils.

> Op 3 jan 2025, om 19:47 heeft Nils Breunese <ni...@breun.nl> het volgende geschreven:
> 
> Thanks for confirming. Should I create a Surefire issue for this?
> 
> Nils.
> 
>> Op 3 jan 2025 om 18:51 heeft Piotr Żygieło <pi...@gmail.com> het volgende geschreven:
>> 
>> On Fri, 3 Jan 2025 at 15:41, Nils Breunese <ni...@breun.nl> wrote:
>>> Thanks for the pointer,
>> 
>> That was not good at all (see below).
>> 
>>> It seems that using <jdkToolchain> in the configuration of the execution for the forked tests requires a local global toolchains.xml
>> 
>> I am observing something similar.
>> 
>>> toolchains:select-jdk-toolchain can auto-detect JDK toolchains
>> 
>> If I *ignore* the link I posted myself, and :select-jdk-toolchain -
>> selected JDK is used as expected across plugins - compiler, surefire,
>> jar etc. So for example starting maven with JDK 11, selecting JDK21 -
>> and compiling for release 21 and then surefire-ing it (w/o any
>> toolchain-related m-surefire-p configuration) - works.
>> 
>> But surefire breaks - as you described - with forking, once
>> _reuseForks=false_ or _forkCount=2_ is set.
>> 
>> Which is very unsatisfactory, as this is logged:
>> 
>> [INFO] --- surefire:3.5.0:test (default-test) @ ... ---
>> [INFO] Toolchain in maven-surefire-plugin:
>> JDK[/usr/lib/jvm/java-21-openjdk-21.0.5.0.11-1.fc40.x86_64]
>> 
>> and then
>> 
>> java.lang.UnsupportedClassVersionError: ... has been compiled by a
>> more recent version of the Java Runtime (class file version 65.0),
>> this version of the Java Runtime only recognizes class file versions
>> up to 55.0
>> 
>> --
>> Piotrek
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Surefire plugin doesn't use toolchain JDK for forked tests?

Posted by Nils Breunese <ni...@breun.nl>.
Thanks for confirming. Should I create a Surefire issue for this?

Nils.

> Op 3 jan 2025 om 18:51 heeft Piotr Żygieło <pi...@gmail.com> het volgende geschreven:
> 
> On Fri, 3 Jan 2025 at 15:41, Nils Breunese <ni...@breun.nl> wrote:
>> Thanks for the pointer,
> 
> That was not good at all (see below).
> 
>> It seems that using <jdkToolchain> in the configuration of the execution for the forked tests requires a local global toolchains.xml
> 
> I am observing something similar.
> 
>> toolchains:select-jdk-toolchain can auto-detect JDK toolchains
> 
> If I *ignore* the link I posted myself, and :select-jdk-toolchain -
> selected JDK is used as expected across plugins - compiler, surefire,
> jar etc. So for example starting maven with JDK 11, selecting JDK21 -
> and compiling for release 21 and then surefire-ing it (w/o any
> toolchain-related m-surefire-p configuration) - works.
> 
> But surefire breaks - as you described - with forking, once
> _reuseForks=false_ or _forkCount=2_ is set.
> 
> Which is very unsatisfactory, as this is logged:
> 
> [INFO] --- surefire:3.5.0:test (default-test) @ ... ---
> [INFO] Toolchain in maven-surefire-plugin:
> JDK[/usr/lib/jvm/java-21-openjdk-21.0.5.0.11-1.fc40.x86_64]
> 
> and then
> 
> java.lang.UnsupportedClassVersionError: ... has been compiled by a
> more recent version of the Java Runtime (class file version 65.0),
> this version of the Java Runtime only recognizes class file versions
> up to 55.0
> 
> --
> Piotrek
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Surefire plugin doesn't use toolchain JDK for forked tests?

Posted by Piotr Żygieło <pi...@gmail.com>.
On Fri, 3 Jan 2025 at 15:41, Nils Breunese <ni...@breun.nl> wrote:
> Thanks for the pointer,

That was not good at all (see below).

> It seems that using <jdkToolchain> in the configuration of the execution for the forked tests requires a local global toolchains.xml

I am observing something similar.

> toolchains:select-jdk-toolchain can auto-detect JDK toolchains

If I *ignore* the link I posted myself, and :select-jdk-toolchain -
selected JDK is used as expected across plugins - compiler, surefire,
jar etc. So for example starting maven with JDK 11, selecting JDK21 -
and compiling for release 21 and then surefire-ing it (w/o any
toolchain-related m-surefire-p configuration) - works.

But surefire breaks - as you described - with forking, once
_reuseForks=false_ or _forkCount=2_ is set.

Which is very unsatisfactory, as this is logged:

[INFO] --- surefire:3.5.0:test (default-test) @ ... ---
[INFO] Toolchain in maven-surefire-plugin:
JDK[/usr/lib/jvm/java-21-openjdk-21.0.5.0.11-1.fc40.x86_64]

and then

java.lang.UnsupportedClassVersionError: ... has been compiled by a
more recent version of the Java Runtime (class file version 65.0),
this version of the Java Runtime only recognizes class file versions
up to 55.0

-- 
Piotrek

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Surefire plugin doesn't use toolchain JDK for forked tests?

Posted by Nils Breunese <ni...@breun.nl>.
Thanks for the pointer, Piotrek. It seems that using <jdkToolchain> in the configuration of the execution for the forked tests requires a local global toolchains.xml, but I was hoping to avoid the need for that, because nowadays toolchains:select-jdk-toolchain can auto-detect JDK toolchains (https://maven.apache.org/plugins/maven-toolchains-plugin/select-jdk-toolchain-mojo.html), and I would like to not force everyone working on these projects to have a local global toolchains.xml both locally and in their CI build environment.

Can you confirm that Surefire forking the Maven runtime JDK instead of the toolchain JDK is intentional behavior? If Surefire would do the latter, which is also what I expected it to do, then I wouldn’t need any additional configuration.

Thanks, Nils.

> Op 3 jan 2025, om 14:59 heeft Piotr Żygieło <pi...@gmail.com> het volgende geschreven:
> 
> On Fri, 3 Jan 2025 at 14:47, Nils Breunese <ni...@breun.nl> wrote:
>> is there something I can do have it use the toolchain JDK for the forked tests
> 
> https://maven.apache.org/surefire/maven-surefire-plugin/examples/toolchains.html
> 
> -- 
> Piotrek
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


Re: Surefire plugin doesn't use toolchain JDK for forked tests?

Posted by Piotr Żygieło <pi...@gmail.com>.
On Fri, 3 Jan 2025 at 14:47, Nils Breunese <ni...@breun.nl> wrote:
>  is there something I can do have it use the toolchain JDK for the forked tests

https://maven.apache.org/surefire/maven-surefire-plugin/examples/toolchains.html

-- 
Piotrek

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org