Skip to content

fix: decouple test-jar skip from maven.test.skip [MJAR-138] - #612

Merged
gnodet merged 1 commit into
apache:masterfrom
gnodet:fix/mjar-138-skip-test-jar
Oct 9, 2026
Merged

gnodet merged 1 commit into
apache:masterfrom
gnodet:fix/mjar-138-skip-test-jar

Conversation

@gnodet

@gnodet gnodet commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #308 / MJAR-138.

The test-jar goal's skip parameter was bound to ${maven.test.skip}. This meant passing -Dmaven.test.skip=true β€” which also skips test compilation β€” silently prevented the test-jar from being built. In multi-module projects where a downstream module has a test-jar dependency, this broke the build.

This is a long-standing (2010) tension between two intentional decisions:

  • MJAR-90: skip the test-jar when maven.test.skip=true to avoid producing an empty test-jar (tests weren't compiled)
  • MJAR-138: but skipping the test-jar breaks cross-module test-jar dependencies

Solution

Rebind skip from ${maven.test.skip} to ${maven.test.jar.skip} (default false).

The MJAR-90 concern (empty test-jar) is already handled by skipIfEmpty in modern versions. There is no longer a reason to couple test-jar packaging to maven.test.skip.

Users who want to skip test-jar packaging should now use -Dmaven.test.jar.skip=true (or <skip>true</skip> in POM config β€” unchanged).

Users who want to skip test execution without breaking downstream modules should use:

  • -DskipTests (Maven 3+)
  • --skip-tests (Maven 4.1+, see #13233)

Changes

  • TestJarMojo: rebind skip property from maven.test.skip β†’ maven.test.jar.skip
  • New IT mjar-138: multi-module build with -DskipTests β€” verifies model test-jar is built and client can compile against it via the reactor

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid fix β€” decoupling skip from maven.test.skip is the right call now that skipIfEmpty handles the empty-test-jar concern from MJAR-90. The IT covers the core scenario well.

One finding on the @since tag.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after 7dee44e β€” the @since tag is now correctly set to 4.0.0-beta-2. No other issues found.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after 7dee44e. Previous finding (incorrect @since 2.2 β†’ @since 4.0.0-beta-2) is addressed.

No new issues. The property rebinding (maven.test.skip β†’ maven.test.jar.skip) is clean, the Javadoc accurately describes the new behavior, and the IT covers the core scenario.

Metadata: no milestone set β€” suggest 4.0.0-beta-2.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@ascheman ascheman added this to the 4.0.0-beta-2 milestone Sep 26, 2026
Comment thread src/it/mjar-138/verify.groovy Resolved
Comment thread src/it/mjar-138/verify.groovy Resolved
Comment thread src/it/mjar-138/verify.groovy Resolved

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after 1a571bc. desruisseaux's isFile() suggestions are both addressed β€” verify.groovy now uses !testJar.isFile() and !clientTestClasses.isFile(). No new issues.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after ec583d2. desruisseaux's assert style suggestion is addressed β€” verify.groovy now uses idiomatic Groovy assertions instead of the if/return false pattern, consistent with newer ITs. All previous findings resolved, no new issues.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@ascheman ascheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks β€” the direction is good: a dedicated maven.test.jar.skip property instead of overloading maven.test.skip, plus the clearer Javadoc. I'm fine with the code change itself.

I do want to push back fairly hard on the integration test, though, because as written it does not cover the fix at all.

src/it/mjar-138 runs clean package -DskipTests. But -DskipTests sets neither the old maven.test.skip binding nor the new maven.test.jar.skip one β€” so skip is false either way, the model test-jar is built and client compiles with and without this change. Revert the one-line property change on TestJarMojo.skip and re-run the IT: it stays green. So the test exercises a path that was never broken by MJAR-138 and does not distinguish the fixed plugin from the unfixed one β€” a green-by-design IT that quietly stops guarding the behavior it is named after.

The honest difficulty here is worth confronting in the test rather than side-stepping:

  • -Dmaven.test.skip=true is what actually triggered MJAR-138, but it also skips test-compilation, so model's test-jar would be empty and client could not resolve TestComponent β€” the build would fail even with the fix.
  • On master skipIfEmpty defaults to false, so after this change -Dmaven.test.skip=true now produces an empty test-jar where before it produced none. The description says skipIfEmpty already handles the empty-test-jar case; with the default that is not so.

Could we please get an IT that actually fails on the unpatched plugin before this lands β€” e.g. assert that -Dmaven.test.jar.skip=true suppresses the test-jar while a normal build (or -DskipTests) still produces it β€” and have both the test and the PR description pin down the maven.test.skip + empty-test-jar contract explicitly?

Happy to write that IT myself and hand it to you (patch against this branch, or a follow-up) if that helps move it along β€” just say the word. The property and doc change are fine; I'd just really prefer not to merge it with a test that proves nothing about the change.

@gnodet gnodet added bug Something isn't working java Pull requests that update Java code labels Oct 9, 2026
@gnodet
gnodet force-pushed the fix/mjar-138-skip-test-jar branch from ec583d2 to 1db81ba Compare October 9, 2026 09:03
The test-jar goal's skip parameter was incorrectly bound to maven.test.skip,
causing jar:test-jar to be skipped when -Dmaven.test.skip=true was passed.
This breaks multi-module builds where a downstream module depends on the
test-jar artifact (the reactor cannot resolve it).

- Rebinds skip to maven.test.jar.skip (default false), decoupling it from
  maven.test.skip which also suppresses test compilation
- Users who relied on -Dmaven.test.skip=true to suppress test-jar packaging
  should switch to -Dmaven.test.jar.skip=true
- Adds IT mjar-138 verifying a multi-module build with -DskipTests still
  produces the test-jar and allows the client module to compile against it
- Fixes @SInCE tag on the skip parameter

Fixes: apache#308
@gnodet
gnodet force-pushed the fix/mjar-138-skip-test-jar branch from 1db81ba to 64b7056 Compare October 9, 2026 09:04
@gnodet
gnodet merged commit 5520b2d into apache:master Oct 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MJAR-138] jar:test-jar is skipped when maven.test.skip=true

4 participants