Skip to content

Warn when the aggregate goal skips a non-pom project - #325

Open
kratos0718 wants to merge 1 commit into
apache:masterfrom
kratos0718:warn-aggregate-non-pom-packaging
Open

Warn when the aggregate goal skips a non-pom project#325
kratos0718 wants to merge 1 commit into
apache:masterfrom
kratos0718:warn-aggregate-non-pom-packaging

Conversation

@kratos0718

Copy link
Copy Markdown
Contributor

Fixes #306.

Problem

AggregatorSourceJarMojo.doExecute() packages sources only when the project uses pom packaging:

if (Type.POM.equals(getProject().getPackaging().type().id())) {
    packageSources(reactorProjects);
}

With any other packaging it returns silently. No source JAR is produced and the user gets no indication why — which, as the issue notes, is a plausible outcome of a misleading build or configuration even though @Mojo(aggregator = true) normally implies pom.

Change

Adds an else branch that logs a warning naming the goal, the required packaging, and the project's actual packaging:

[WARNING] Not packaging aggregated sources: the aggregate goal requires "pom"
packaging, but this project uses "jar" packaging.

The goal name is now a constant shared by the @Mojo annotation and the message, so the two cannot drift apart.

On warning vs failing

@elharo asked in the issue whether this should fail rather than log. I went with a warning, for the reason discussed there: a non-pom aggregator run succeeds today, so failing would turn currently-green builds red without any change on the user's side, and the people most likely to hit it are exactly those with an incidental binding they never noticed. The complaint in the issue is diagnosability, which the warning resolves fully.

If the project would rather treat it as an outright misconfiguration, I am happy to switch this to a failure — I would just suggest tying that to a major version. Say the word and I will push the change.

Tests

AggregatorSourceJarMojoTest adds two cases:

  • warnsWhenPackagingIsNotPom — asserts the warning is emitted and contains the goal, the required packaging and the actual packaging
  • doesNotWarnWhenPackagingIsPom — asserts no warning on a legitimate pom run, so the change cannot over-correct into warning on valid builds
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Behaviour for pom packaging is unchanged.

AggregatorSourceJarMojo.doExecute() packaged sources only for "pom"
packaging and returned silently otherwise, so a project with an
incidental aggregator binding produced no source JAR and no indication
why.

Add an else branch logging a warning that names the goal, the required
packaging and the project's actual packaging. Behaviour is otherwise
unchanged: the build still succeeds, so no currently-passing build turns
red.

The goal name is now a constant shared by the @mojo annotation and the
message so the two cannot drift apart.
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.

AggregatorSourceJarMojo silently does nothing for non-POM packaging

1 participant