Injecting default Maven project into other Maven components

237 Views Asked by At

I am developing a Maven plugin and I make use of the Assembly API to do some custom assembly construction. When my code runs, I get this stack trace:

java.lang.NullPointerException: null
    at org.apache.maven.plugin.assembly.interpolation.AssemblyInterpolator.buildInterpolator(AssemblyInterpolator.java:177)
    at org.apache.maven.plugin.assembly.interpolation.AssemblyExpressionEvaluator.(AssemblyExpressionEvaluator.java:44)
    at org.apache.maven.plugin.assembly.io.DefaultAssemblyReader.mergeComponentsWithMainAssembly(DefaultAssemblyReader.java:470)
    at org.apache.maven.plugin.assembly.io.DefaultAssemblyReader.readAssembly(DefaultAssemblyReader.java:390)
    at org.apache.maven.plugin.assembly.io.DefaultAssemblyReader.addAssemblyFromDescriptor(DefaultAssemblyReader.java:328)
    at org.apache.maven.plugin.assembly.io.DefaultAssemblyReader.readAssemblies(DefaultAssemblyReader.java:120)

From what I can tell, this is caused by DefaultAssemblyReader not having access to the default Maven project for the plugin. In my mojo, I have declared the Maven project and assembly reader like this:

@Component (role=org.apache.maven.project.MavenProject.class, hint="default")
protected MavenProject project;

@Component(role=org.apache.maven.plugin.assembly.io.AssemblyReader.class, hint="default")
protected AssemblyReader defaultReader;

The AssemblyReader class doesn't have any setter to set the project on it, and I'm not sure how I can get project injected in to defaultReader. One solution I thought of would be to extend SingleAssemblyMojo and give it a setter for the project and pass that configuration object to the assembly reader, but that seems like a bit of a kludge. Is there a more elegant/proper way?

0

There are 0 best solutions below