Skip to content

Mutate the main variant's artifact where java-test-fixtures puts it on the test classpath - #29

Merged
vlsi merged 1 commit into
cribro-dev:mainfrom
vlsi:fix-pitest-main-jar
Nov 30, 2026
Merged

vlsi merged 1 commit into
cribro-dev:mainfrom
vlsi:fix-pitest-main-jar

Conversation

@vlsi

@vlsi vlsi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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 testRuntimeClasspath 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 (capability <group>:<name>-test-fixtures) 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, so the Maven goal is unaffected.

Where the 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 (and skips every jar), so it would mutate Gradle's build/classes/java/test. This is a change from 1.2.0, which finished such a run with "no mutant":

Found none of the main classes on the test runtime classpath of :pitestDiff. The classpath holds neither the directories [<project>/build/classes/java/main] 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(...).

The guide's Limits section says which entries pitestDiff mutates and quotes the failure.

The TestKit tests run on the build's Gradle 9 only. I ran aJarOfAnotherTaskIsMutatedWhereRuntimeElementsPublishesIt and theJarTasksArchiveIsMutatedWhenTheConfigurationCacheIsReused once on Gradle 8.14.3 with JDK 17 (withGradleVersion("8.14.3"), org.gradle.java.home in the test build), and both passed.

Scope. PIT splits --mutableCodePaths at 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

@vlsi
vlsi force-pushed the fix-pitest-main-jar branch from a55ff36 to b2d8f74 Compare November 30, 2026 12:16
@vlsi vlsi changed the title Mutate the module's jar where java-test-fixtures puts it on the test classpath Mutate the main variant's artifact where java-test-fixtures puts it on the test classpath Nov 30, 2026
…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
vlsi force-pushed the fix-pitest-main-jar branch from b2d8f74 to 1b965d5 Compare November 30, 2026 17:38
@vlsi
vlsi merged commit f722b5f into cribro-dev:main Nov 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant