Skip to content

Warn when aggregate runs on non-POM packaging - #320

Open
kratos0718 wants to merge 1 commit into
apache:masterfrom
kratos0718:fix/306-aggregate-warns-on-non-pom-packaging
Open

Warn when aggregate runs on non-POM packaging#320
kratos0718 wants to merge 1 commit into
apache:masterfrom
kratos0718:fix/306-aggregate-warns-on-non-pom-packaging

Conversation

@kratos0718

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

Add the else branch and warn, naming the project and its actual packaging so the message says what to change. The wording follows the classifier warning packageSources already emits.

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 packages nothing and warns, with the message naming the packaging and the project

The second fails against the silent version with Wanted but not invoked; the first passes either way, since that branch is unchanged. mvn verify -DskipITs: 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.

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

2 participants