apache/maven · error · IllegalStateException
No instance of {} is bound to the mojo execution scope.
Error message
No instance of {} is bound to the mojo execution scope. What it means
MojoExecutionScope.seededKeySupplier is the placeholder supplier registered for mojo-execution-scoped keys. If such a key is resolved while the scope is active but the instance was never seeded for the current mojo execution, the supplier fires and throws IllegalStateException naming the class — meaning the mojo execution scope has no binding for that type.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/di/MojoExecutionScope.java:57
private final Map<Key<?>, Object> provided = new HashMap<>();
public <T> void seed(Class<T> clazz, Supplier<T> value) {
seeded.put(Key.of(clazz), value);
}
public Collection<Object> provided() {
return provided.values();
}
}
private final ThreadLocal<LinkedList<ScopeState>> values = new ThreadLocal<>();
public MojoExecutionScope() {}
public static <T> Supplier<T> seededKeySupplier(Class<? extends T> clazz) {
return () -> {
throw new IllegalStateException(
"No instance of " + clazz.getName() + " is bound to the mojo execution scope.");
};
}
public void enter() {
LinkedList<ScopeState> stack = values.get();
if (stack == null) {
stack = new LinkedList<>();
values.set(stack);
}
stack.addFirst(new ScopeState());
}
protected ScopeState getScopeState() {
LinkedList<ScopeState> stack = values.get();
if (stack == null || stack.isEmpty()) {
throw new IllegalStateException();
}View on GitHub (pinned to e4093d4e12)
Solutions
- Move the dependency access inside mojo execution — inject it as a field of the Mojo so Maven seeds it during setup, rather than looking it up manually
- Fix the binding so the key is bound (not merely seeded) with an appropriate scope
- In tests, wrap resolution with scope.enter(); scope.seed(Key.get(Type.class), instance); ... finally scope.exit()
Example fix
// before: resolving a mojo-scoped bean manually
MyComponent c = injector.getInstance(MyComponent.class); // seeded placeholder fires
// after: let Maven seed it during mojo execution
@Mojo(name = "go", requiresDependencyResolution = ResolutionScope.RUNTIME)
public class MyMojo extends AbstractMojo {
private final MyComponent c; // injected, seeded by MojoExecutionScope
@Inject
public MyMojo(MyComponent c) { this.c = c; }
} Defensive patterns
Strategy: validation
Validate before calling
// in tests: seed the mojo execution scope before resolving
mojoExecutionScope.enter();
try {
mojoExecutionScope.seed(MyComponent.class, new MyComponentImpl());
MyComponent c = injector.getInstance(MyComponent.class);
} finally {
mojoExecutionScope.exit();
} Try / catch
try {
MyComponent c = injector.getInstance(MyComponent.class);
} catch (IllegalStateException e) {
if (e.getMessage() != null && e.getMessage().contains("mojo execution scope")) {
// instance never seeded for this execution; request it via Mojo injection instead
throw new IllegalStateException("Resolve this dependency inside the mojo execution via field injection", e);
}
throw e;
} Prevention
- Inject mojo-scoped dependencies as Mojo fields so Maven seeds them during execution
- Never resolve mojo-scoped keys during project setup or plugin metadata parsing
- In tests, always bracket with enter()/seed()/exit()
When it happens
Trigger: Injecting or looking up a MojoExecutionScope-scoped dependency outside Maven's per-mojo enter()/seed() cycle (e.g. during project setup, plugin configuration, or static init); a custom Sisu binding resolving the raw seeded key before Maven seeds it; tests resolving mojo-scoped beans without seeding.
Common situations: Plugins or extensions requesting mojo-scoped objects too early; test harnesses wiring components with mojo scope but instantiating them directly; refactors that moved a lookup out of execute().
Related errors
- Cannot access {} outside of a scoping block
- Cannot access session scope outside of a scoping block
- No instance of ${clazz.getName()} is bound to the session sc
- Unable to lookup Mojo
- Cannot rebind scope annotation class to a different implemen
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/a89472938257fbb0.
Report an issue: GitHub.