Skip to content

Fork test-jar to generate-test-sources - #319

Closed
kratos0718 wants to merge 1 commit into
apache:masterfrom
kratos0718:fix/304-test-jar-fork-generate-test-sources
Closed

Fork test-jar to generate-test-sources#319
kratos0718 wants to merge 1 commit into
apache:masterfrom
kratos0718:fix/304-test-jar-fork-generate-test-sources

Conversation

@kratos0718

Copy link
Copy Markdown
Contributor

Fixes #304

Problem

TestSourceJarMojo packages test sources, but forks only to generate-sources:

@Mojo(name = "test-jar", defaultPhase = "package")
@Execute(phase = "generate-sources")

Test sources contributed by another plugin bound to generate-test-sources do not exist yet when the mojo runs, so they are missing from the test-sources jar. TestSourceGeneratedJarMojo packages the same content and already forks to generate-test-sources.

Fix

Fork to generate-test-sources. It comes later in the default lifecycle, so everything the previous fork covered is still covered — the change only widens the forked build.

Testing

The test-jar IT only generated sources in generate-sources, so it passed either way and did not pin the fork phase. It now also has a generate-test-sources execution and asserts that its output reaches the jar, mirroring what the test-jar-generated IT already does for generated-test-jar.

Against the current generate-sources fork the extended IT fails on exactly that entry, with the rest of the jar intact:

Checking for existence of META-INF/MANIFEST.MF
Checking for existence of MyTest.java
Checking for existence of test.properties
Checking for existence of generated.properties
Checking for existence of generate-test-sources.properties
FAILURE!

The build plan shows the cause — the forked build stops before the new execution:

--- init fork of ...:test-jar for ...:test-jar (default-cli) ---
Goal: maven-antrun-plugin:1.3:run (generated-sources)
--- exit fork ---

With the fix, test-jar, test-jar-generated, test-jar-no-fork and test-jar-classifier all pass, along with the 10 unit tests. Run on Maven 4.0.0-beta-3.

TestSourceJarMojo packages test sources but forked only to
generate-sources. Test sources contributed by another plugin bound to
generate-test-sources therefore did not exist yet when the mojo ran, and
were missing from the test-sources jar. TestSourceGeneratedJarMojo, which
packages the same content, already forks to generate-test-sources.

Fork to generate-test-sources. That phase comes later in the default
lifecycle, so everything the previous fork covered is still covered.

The test-jar IT only generated sources in generate-sources, so it passed
either way. Add a generate-test-sources execution mirroring the one the
test-jar-generated IT already uses, and assert its output is in the jar.
@kratos0718

Copy link
Copy Markdown
Contributor Author

Closing — #316 was already open for this and I missed it before starting. Apologies for the duplicate noise.

For whatever it is worth, the one thing here that is not in #316 is that the existing test-jar IT passes either way today, since it only generates sources in generate-sources. #316 adds a separate test-jar-generate-test-sources IT, which covers the fix; extending the existing one as well would also stop it silently agreeing with a future regression. Entirely your call whether that is worth a follow-up.

@kratos0718 kratos0718 closed this Aug 6, 2026
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.

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

1 participant