apache/maven · error · PluginContainerException
Unable to lookup Mojo
Error message
Unable to lookup Mojo
What it means
While loading a Maven-4-style mojo, the Sisu injector's getInstance call on the implementation class (keyed with the descriptor's role hint) threw: the mojo class could not be instantiated - constructor failure, missing binding for an injected parameter, or a hint/annotation mismatch. Any such failure is wrapped in PluginContainerException 'Unable to lookup Mojo'.
Source
Thrown at impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java:576
LoggerFactory.getLogger(mojoExecution.getMojoDescriptor().getFullGoalName()));
try {
Injector injector = Injector.create();
injector.discover(pluginRealm);
// Add known classes
// TODO: get those from the existing plexus scopes ?
injector.bindInstance(Session.class, sessionV4);
injector.bindInstance(Project.class, project);
injector.bindInstance(org.apache.maven.api.MojoExecution.class, execution);
injector.bindInstance(org.apache.maven.api.plugin.Log.class, log);
Map<Class<? extends Service>, Supplier<? extends Service>> services = sessionV4.getAllServices();
services.forEach((itf, svc) -> injector.bindSupplier((Class<Service>) itf, (Supplier<Service>) svc));
mojo = mojoInterface.cast(injector.getInstance(
Key.of(mojoDescriptor.getImplementationClass(), mojoDescriptor.getRoleHint())));
} catch (Exception e) {
throw new PluginContainerException(mojoDescriptor, pluginRealm, "Unable to lookup Mojo", e);
}
XmlNode dom = mojoExecution.getConfiguration() != null
? mojoExecution.getConfiguration().getDom()
: null;
PlexusConfiguration pomConfiguration;
if (dom == null) {
pomConfiguration = new DefaultPlexusConfiguration("configuration");
} else {
pomConfiguration = XmlPlexusConfiguration.toPlexusConfiguration(dom);
}
ExpressionEvaluator expressionEvaluator =
new PluginParameterExpressionEvaluatorV4(sessionV4, project, execution);
for (MavenPluginConfigurationValidator validator : configurationValidators) {View on GitHub (pinned to e4093d4e12)
Solutions
- Unwrap the cause chain - the nested exception is the real reason (missing binding, constructor exception, hint mismatch).
- If the hint mismatched, clean-rebuild the plugin so plugin.xml and @Named agree.
- Ensure the mojo class is concrete with an injectable constructor (no-arg or @Inject).
- Check that every service injected into the mojo is provided by the realm or by Maven core.
Example fix
// before: plugin.xml role hint is "my-goal" but the class says
@Named("myMojo")
class MyMojo extends AbstractMojo {}
// after: names agree (and rebuild so the descriptor matches)
@Named("my-goal")
class MyMojo extends AbstractMojo {} Defensive patterns
Strategy: validation
Validate before calling
// run inside the plugin's test suite: fail fast when the mojo cannot be wired
@Test void mojoIsInstantiable() {
Injector i = Guice.createInjector(
new WireModule(new ClassSpaceModule(new URLClassSpace(getClass().getClassLoader()))));
MyMojo mojo = i.getInstance(Key.of(MyMojo.class, "my-goal"));
assertNotNull(mojo);
} Try / catch
try {
mojo = pluginManager.getConfiguredMojo(mojoInterface, session, mojoExecution);
} catch (PluginContainerException e) {
Throwable root = e;
while (root.getCause() != null) root = root.getCause();
// root is the real instantiation failure (binding/constructor/hint): fix the plugin, not the POM
throw new IllegalStateException("mojo wiring failed: " + root, e);
} Prevention
- Keep maven-plugin-plugin and maven-plugin-annotations versions aligned
- Avoid logic in mojo constructors; initialize inside execute()
- Run injector smoke tests in plugin CI so lookup failures never reach users
When it happens
Trigger: The mojo constructor or a field initializer throws; the @Named value on the mojo no longer matches the role hint recorded in plugin.xml; a required injected service has no binding in the realm; the descriptor names an abstract class as implementation.
Common situations: Plugin rebuilt without regenerating plugin.xml after renames; descriptors and annotations produced by mismatched maven-plugin-plugin versions; environments missing a service the mojo expects.
Related errors
- No instance of {} is bound to the mojo execution scope.
- Cannot read metadata from '{}'
- Unable to lookup org.eclipse.aether.RepositorySystem
- Found duplicated phase '{}' in '{}' lifecycle
- No binding to construct an instance for key {}. Existing bi
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/27c3f6adf5eadbbe.
Report an issue: GitHub.