Skip to content

Fix TestSourceJarMojo execute phase to generate-test-sources - #316

Open
elharo wants to merge 3 commits into
masterfrom
fix/test-source-jar-execute-phase
Open

Fix TestSourceJarMojo execute phase to generate-test-sources#316
elharo wants to merge 3 commits into
masterfrom
fix/test-source-jar-execute-phase

Conversation

@elharo

@elharo elharo commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #304

The TestSourceJarMojo was forking to generate-sources instead of generate-test-sources. This caused test sources generated by other plugins in the generate-test-sources phase to not be available when the mojo runs, leading to an empty or incomplete test sources JAR.

Changes

  • Changed @execute(phase = generate-sources) to @execute(phase = generate-test-sources) in TestSourceJarMojo.java
  • Added unit test testExecutePhase to verify the correct phase is used
  • Added integration test test-jar-generate-test-sources to verify the fix works end-to-end

Unit Test

The test testExecutePhase verifies that TestSourceJarMojo has @execute(phase = generate-test-sources). The test fails before the fix and passes after.

Integration Test

The integration test test-jar-generate-test-sources uses maven-antrun-plugin to generate a file in the generate-test-sources phase and verifies it is included in the test sources JAR. Before the fix, the test-jar goal forks to generate-sources, so the antrun execution does not run and the generated file is not in the JAR. After the fix, the test-jar goal forks to generate-test-sources, so the antrun execution runs and the generated file is in the JAR.

Note: The integration test requires Maven 4.0.0-beta-3 to run.

Closes #304

The TestSourceJarMojo was forking to generate-sources instead of
generate-test-sources. This caused test sources generated by other
plugins in the generate-test-sources phase to not be available when
the mojo runs, leading to an empty or incomplete test sources JAR.

- Changed @execute(phase = generate-sources) to
  @execute(phase = generate-test-sources)
- Added test to verify the correct phase is used
@elharo elharo added the bug Something isn't working label Aug 4, 2026
elharo and others added 2 commits August 4, 2026 15:08
This integration test verifies that TestSourceJarMojo forks to
generate-test-sources phase. It uses maven-antrun-plugin to generate
a file in generate-test-sources phase and verifies it is included
in the test sources JAR.

Before the fix, the test-jar goal forks to generate-sources, so the
antrun execution in generate-test-sources phase does not run and the
generated file is not in the JAR. After the fix, the test-jar goal
forks to generate-test-sources, so the antrun execution runs and the
generated file is in the JAR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestSourceJarMojo forks to generate-sources instead of generate-test-sources

1 participant