I have two plugins that are using same duplicated methods. I want to refactor then and move that methods to a shared class and host it in a dependency jar.
Those method required some maven properties as MavenProject, PluginDescriptor and some others maven classes that used to be injected into the mojo.
Is there anyway of such properties to be injected directly in the shared class?
or do I need to inject them into the mojo and then call some initialization method?
I declared the shared class with @Named and created a constructor with @Inject. The mojo class has a contructor too (the code below). Then I tried run it. All the values are being inject into the mojo properly but the shared class object inner properties values are null.
@Inject
public SharedValidationHelperDefault(final MavenProject project,
final BuildContext buildContext,
final RuntimeInformation runtimeInformation, final Log log) {
this.buildContext = buildContext;
this.project = project;
this.runtimeInformation = runtimeInformation;
this.log = log;
}
...
@Inject
public AbstractContainerPackMojo(
final RuntimeInformation runtimeInformation,
final MavenProjectHelper projectHelper,
final BuildContext buildContext, SharedValidationHelper validationHelper) {
this.validationHelper = validationHelper;
this.buildContext = buildContext;
this.runtimeInformation = runtimeInformation;
this.projectHelper = projectHelper;
}