Repository navigation
Mirror the mojo's injected constructor in the generated v4 factory - #1236
Open
CaptainAni187 wants to merge 1 commit into
Open
CaptainAni187 wants to merge 1 commit into
CaptainAni187 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
NoSuchMethodErrorwhen the goal ran.The factory constructor now mirrors the constructor DI would use on the mojo: the
@Injectone, otherwise the no-arg one, otherwise the only one. It keeps the generic signature and the constructor and parameter annotations, so qualifiers like@Namedstill apply, and passes the arguments tosuper(...). A mojo with a no-arg constructor and no@Injectconstructor gets the same factory as before. If no constructor can be picked (several without@Inject, or more than one with it), thedescriptorgoal 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: