Repository navigation
Mutate the main variant's artifact where java-test-fixtures puts it on the test classpath - #29
Merged
Merged
Conversation
vlsi
force-pushed
the
fix-pitest-main-jar
branch
from
November 30, 2026 12:16
a55ff36 to
b2d8f74
Compare
…n the test classpath
In a module that applies java-test-fixtures, Gradle puts the module's
artifact, by default the jar task's archive, on the test runtime
classpath in place of build/classes/java/main. pitestDiff passed PIT
only the main classes directories as --mutableCodePaths, so PIT found
none of the changed classes on the classpath the tests run with, and
every such module reported:
no mutant: no changed line has bytecode PIT may mutate
Apache JMeter applies java-test-fixtures to its core, components, and
jorphan modules, among others, and pitestDiff found no mutant in them.
pitestDiff now passes PIT the entries of the test runtime classpath
that hold the main classes: the main classes directories, and the
artifacts the test runtime classpath configuration resolves to whose
component is this project and whose variant is the project's main
variant, the one with the capability <group>:<name>. That covers the
jar task's archive and any other file runtimeElements publishes, such
as a fat jar or a jar a Copy task writes. The test fixtures' jar
carries the capability <group>:<name>-test-fixtures and is left out.
Naming the jar task instead was rejected: a build that replaces the
runtimeElements artifact puts another file on the classpath.
PitestDiffMojo already maps each reactor artifact to its output
directory, whatever built it.
Where the test runtime classpath holds neither, the task fails before
PIT starts. Given an empty --mutableCodePaths, PIT falls back to
DefaultCodePathPredicate, which admits every class directory whose
path does not end in test-classes or bin-test, so it would mutate
build/classes/java/test.
User-visible:
pitestDiff reports the mutants of a module that applies java-test-fixtures, where 1.2.0 reported "no mutant: no changed line has bytecode PIT may mutate".
pitestDiff fails where sourceSets.test.runtimeClasspath holds neither the main classes directories nor the project's own jar resolved through testRuntimeClasspath, where 1.2.0 finished with "no mutant: no changed line has bytecode PIT may mutate". The failure is: "Found none of the main classes on the test runtime classpath of <task path>. The classpath holds neither the directories [<main classes dirs>] nor the project's own jar resolved through configurations.testRuntimeClasspath, such as the one java-test-fixtures puts there, so PIT would have no class to mutate. Add the directories to sourceSets.test.runtimeClasspath, the classpath pitestDiff runs the tests with under PIT. PIT then mutates the main classes even where the tests load them from another file, such as a jar added with files(...)."
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vlsi
force-pushed
the
fix-pitest-main-jar
branch
from
November 30, 2026 17:38
b2d8f74 to
1b965d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a module that applies
java-test-fixtures, Gradle puts the module's artifact (by default thejartask's archive) on the test runtime classpath in place ofbuild/classes/java/main.pitestDiffpassed PIT only the main classes directories as--mutableCodePaths, so PIT found none of the changed classes on the classpath the tests run with, and every such module reported:Apache JMeter applies
java-test-fixturesto itscore,components, andjorphanmodules, among others, andpitestDifffound no mutant in them.pitestDiffnow passes PIT the entries of the test runtime classpath that hold the main classes: the main classes directories, and the artifacts thetestRuntimeClasspathconfiguration resolves to whose component is this project and whose variant is the project's main variant, the one with the capability<group>:<name>. That covers thejartask's archive and any other fileruntimeElementspublishes, such as a fat jar or a jar aCopytask writes; the test fixtures' jar (capability<group>:<name>-test-fixtures) is left out. Naming thejartask instead was rejected: a build that replaces theruntimeElementsartifact puts another file on the classpath.PitestDiffMojoalready maps each reactor artifact to its output directory, whatever built it, so the Maven goal is unaffected.Where the classpath holds neither, the task fails before PIT starts. Given an empty
--mutableCodePaths, PIT falls back toDefaultCodePathPredicate, which admits every class directory whose path does not end intest-classesorbin-test(and skips every jar), so it would mutate Gradle'sbuild/classes/java/test. This is a change from 1.2.0, which finished such a run with "no mutant":The guide's Limits section says which entries
pitestDiffmutates and quotes the failure.The TestKit tests run on the build's Gradle 9 only. I ran
aJarOfAnotherTaskIsMutatedWhereRuntimeElementsPublishesItandtheJarTasksArchiveIsMutatedWhenTheConfigurationCacheIsReusedonce on Gradle 8.14.3 with JDK 17 (withGradleVersion("8.14.3"),org.gradle.java.homein the test build), and both passed.Scope. PIT splits
--mutableCodePathsat commas and matches each entry as a glob, so a project path containing,,*, or?matches nothing. That was already true for the directories before this change and is left for a separate issue.🤖 Generated with Claude Code