Skip to content

Fail the aggregate goal for non-POM packaging - #320

Merged
elharo merged 3 commits into
apache:masterfrom
kratos0718:fix/306-aggregate-warns-on-non-pom-packaging
Sep 27, 2026
Merged

elharo merged 3 commits into
apache:masterfrom
kratos0718:fix/306-aggregate-warns-on-non-pom-packaging

Conversation

@kratos0718

@kratos0718 kratos0718 commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #306

Problem

AggregatorSourceJarMojo.doExecute() packages sources only for pom packaging:

protected void doExecute() throws MojoException {
    if (Type.POM.equals(getProject().getPackaging().type().id())) {
        packageSources(reactorProjects);
    }
}

Any other packaging falls off the end of the method. No archive is produced and nothing is logged, so there is no way to tell the skip apart from a build that simply did not reach the goal.

Fix

A non-POM project has nothing to aggregate, so the goal now throws a MojoException naming the project and its actual packaging. The goal is aggregator = true, so it runs once at the top of the build rather than on each inherited module.

Testing

AggregatorSourceJarMojoTest covers both branches, overriding packageSources to record the projects it receives rather than building an archive:

  • pom packaging still packages the reactor projects, and logs nothing
  • non-POM packaging throws, packages nothing, and the message names the packaging and the project

mvn test: 12 tests, all passing.

AggregatorSourceJarMojo.doExecute() packages sources only for pom
packaging and otherwise returns without a word, so a project that reaches
the goal with some other packaging gets no source archive and no
indication of why.

Warn instead, naming the project and its actual packaging, in the style
of the classifier warning packageSources already emits.
if (Type.POM.equals(type)) {
packageSources(reactorProjects);
} else {
getLog().warn("NOT aggregating sources as this goal requires a project with [" + Type.POM

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.

I'm unsure about this. Maybe debug level? I don't know.

@kratos0718

Copy link
Copy Markdown
Contributor Author

Debug would leave it effectively silent, which is the thing #306 is about — nobody runs with -X unless they already suspect something is wrong, and the whole failure mode here is that you have no reason to suspect anything. The build succeeds and no source jar appears.

Warn felt right because it only fires when the goal was asked to do something it cannot do, so it isn't noise on a normal build. Your issue also suggested "a warning or info message", which is where I took it from.

That said, info is a reasonable middle if warn feels too loud — it still shows on a default run. Say the word and I'll switch it.

@kratos0718

Copy link
Copy Markdown
Contributor Author

@elharo just following up, did you have a preference between warn and info for this, or is warn fine as is? Happy to switch it either way, just want to close this out.

aggregate is often declared in a parent POM and inherited by jar
modules, where the skip is expected, so warn would flag every one of
them. info matches the plugin's other expected-skip messages ("Skipping
source per configuration", "NOT adding java-sources ...") and stays
visible at the default log level, unlike debug.
@kratos0718

Copy link
Copy Markdown
Contributor Author

Good call. aggregate is often declared in a parent POM and inherited by jar modules, and a warning would fire on every one of them. I switched it to info, which is what the plugin already uses for its other expected skips like "Skipping source per configuration" and "NOT adding java-sources". It still shows at the default log level, so the skip is no longer silent, which is what #306 was about.

@kratos0718 kratos0718 changed the title Warn when aggregate runs on non-POM packaging Log when aggregate skips non-POM packaging Sep 27, 2026

@elharo elharo 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.

The more I look at this the more I'm convinced this case should simply fail, i.e. throw an exception.

Unless there's some reason devs need to aggregate a non-pom project that aggregates nothing, but I can't think of one.

There is nothing to aggregate in a project without POM packaging, so
stop the build with a message naming the project and its packaging
instead of skipping.
@kratos0718 kratos0718 changed the title Log when aggregate skips non-POM packaging Fail the aggregate goal for non-POM packaging Sep 27, 2026
@kratos0718

Copy link
Copy Markdown
Contributor Author

Agreed, since the goal is an aggregator it only runs once at the top of the build, so failing there shouldn't break anyone's inherited modules. It now throws a MojoException naming the project and its packaging, and the test checks for that. I updated the title and description to match.

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified, and both packaging branches are covered by tests.

Review effort: Lite
Findings: None

What changed in this PR

Updates the aggregate source goal to fail clearly for non-POM packaging instead of silently skipping.

Changes:

  • Adds descriptive validation for unsupported packaging.
  • Adds tests for POM and non-POM behavior.
File Description
src/​test/​java/​org/​apache/​maven/​plugins/​source/​AggregatorSourceJarMojoTest.java Tests successful aggregation and failure behavior.
src/​main/​java/​org/​apache/​maven/​plugins/​source/​AggregatorSourceJarMojo.java Validates packaging before aggregation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@elharo
elharo merged commit 80c9647 into apache:master Sep 27, 2026
8 checks passed
@github-actions github-actions Bot added this to the 4.0.0 milestone Sep 27, 2026
@github-actions

Copy link
Copy Markdown

@elharo Please assign appropriate label to PR according to the type of change.

@elharo elharo added the bug Something isn't working label Sep 27, 2026
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.

AggregatorSourceJarMojo silently does nothing for non-POM packaging

3 participants