Visitar URL original
Mirror the mojo's injected constructor in the generated v4 factory by CaptainAni187 · Pull Request #1236 · apache/maven-plugin-tools · GitHub
Skip to content

Mirror the mojo's injected constructor in the generated v4 factory - #1236

Open
CaptainAni187 wants to merge 1 commit into
apache:masterfrom
CaptainAni187:fix-v4-factory-constructor-injection
Open

CaptainAni187 wants to merge 1 commit into
apache:masterfrom
CaptainAni187:fix-v4-factory-constructor-injection

Conversation

@CaptainAni187

Copy link
Copy Markdown

Fixes #1229.

The factory generated for a Maven 4 API mojo always called the mojo's no-arg constructor, so a mojo using constructor injection built fine and then failed with NoSuchMethodError when the goal ran.

The factory constructor now mirrors the constructor DI would use on the mojo: the @Inject one, otherwise the no-arg one, otherwise the only one. It keeps the generic signature and the constructor and parameter annotations, so qualifiers like @Named still apply, and passes the arguments to super(...). A mojo with a no-arg constructor and no @Inject constructor gets the same factory as before. If no constructor can be picked (several without @Inject, or more than one with it), the descriptor goal fails with a message instead of producing a plugin that breaks at run time.

The new tests build the mojo classes with ASM, so the Maven 4 API isn't needed on the test classpath. I also ran the reproducer from the issue on Maven 4.0.0-rc-7: it fails with 4.0.0-beta-3 and runs with this change.


To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following:

The factory generated for a Maven 4 API mojo always called the mojo's
no-arg constructor, so a mojo using constructor injection built fine
and then failed at run time with NoSuchMethodError.

The factory constructor now mirrors the constructor DI would pick on
the mojo (the @Inject one, else the no-arg one, else the only one),
with the same generic signature and annotations, and passes its
arguments to super. A mojo with no usable constructor fails the
descriptor goal instead.

Fixes apache#1229

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

LGTM. Correct bytecode generation for constructor-injected v4 mojo factories. Slot arithmetic, annotation copying, and constructor selection logic are all sound; the test suite validates wide types, annotation preservation, priority rules, and error cases.

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

@slachiewicz slachiewicz added the bug Something isn't working label Oct 29, 2026
@CaptainAni187

Copy link
Copy Markdown
Author

@gnodet thanks for the approval! Is there anything else needed before this can be merged?

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.

Generated factory for a Maven 4 API mojo requires a no-arg constructor

4 participants