szpak / gradle-pitest-plugin

Gradle plugin for PIT Mutation Testing
http://gradle-pitest-plugin.solidsoft.info/
212 stars 57 forks source link

PitestTask should run PIT using Java pointed in toolchain set for project execution #301

Open szpak opened 2 years ago

szpak commented 2 years ago

Based on my tries with using Java toolchain for testing the plugin itself, it seems that PIT in PitestTask is executed with the JVM which was used to start the Gradle process, not the one selected with the toolchain options.

JavaExec in Gradle 6.9.1 allows to set javaLauncher, so it should be possible to achieve: https://docs.gradle.org/current/userguide/toolchains.html#sec:plugins

Update. The PoC confirmed that, however, there is some more work around to make it usable for CI and for external contributors.

LarsEckart commented 2 years ago

Just wanted to comment that I recently ran into this issue. I've a project that uses gradle toolchain set to jdk 17, and this is also my default jdk on classpath. When working on that project, others who had jdk11 on their classpath, they could run pitest but all they saw was a report with 0 coverage and in logs they could read Could not load kata.Application kata/Application 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.

danishnawab commented 2 months ago

For anyone running into this issue, you can configure the jvmPath to the default toolchain launcher.

pitest {
    ...
    jvmPath = javaToolchains.launcherFor { languageVersion = java.toolchain.languageVersion }.get().executablePath
    ...
}