{"record":{"id":"a89472938257fbb0","repo":"apache/maven","slug":"no-instance-of-is-bound-to-the-mojo-execution-s","errorCode":null,"errorMessage":"No instance of {} is bound to the mojo execution scope.","messagePattern":"No instance of (.+?) is bound to the mojo execution scope\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/di/MojoExecutionScope.java","lineNumber":57,"sourceCode":"\n        private final Map<Key<?>, Object> provided = new HashMap<>();\n\n        public <T> void seed(Class<T> clazz, Supplier<T> value) {\n            seeded.put(Key.of(clazz), value);\n        }\n\n        public Collection<Object> provided() {\n            return provided.values();\n        }\n    }\n\n    private final ThreadLocal<LinkedList<ScopeState>> values = new ThreadLocal<>();\n\n    public MojoExecutionScope() {}\n\n    public static <T> Supplier<T> seededKeySupplier(Class<? extends T> clazz) {\n        return () -> {\n            throw new IllegalStateException(\n                    \"No instance of \" + clazz.getName() + \" is bound to the mojo execution scope.\");\n        };\n    }\n\n    public void enter() {\n        LinkedList<ScopeState> stack = values.get();\n        if (stack == null) {\n            stack = new LinkedList<>();\n            values.set(stack);\n        }\n        stack.addFirst(new ScopeState());\n    }\n\n    protected ScopeState getScopeState() {\n        LinkedList<ScopeState> stack = values.get();\n        if (stack == null || stack.isEmpty()) {\n            throw new IllegalStateException();\n        }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/di/MojoExecutionScope.java#L39-L75","documentation":"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.","triggerScenarios":"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.","commonSituations":"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().","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()"],"exampleFix":"// before: resolving a mojo-scoped bean manually\nMyComponent c = injector.getInstance(MyComponent.class); // seeded placeholder fires\n\n// after: let Maven seed it during mojo execution\n@Mojo(name = \"go\", requiresDependencyResolution = ResolutionScope.RUNTIME)\npublic class MyMojo extends AbstractMojo {\n    private final MyComponent c; // injected, seeded by MojoExecutionScope\n    @Inject\n    public MyMojo(MyComponent c) { this.c = c; }\n}","handlingStrategy":"validation","validationCode":"// in tests: seed the mojo execution scope before resolving\nmojoExecutionScope.enter();\ntry {\n    mojoExecutionScope.seed(MyComponent.class, new MyComponentImpl());\n    MyComponent c = injector.getInstance(MyComponent.class);\n} finally {\n    mojoExecutionScope.exit();\n}","typeGuard":null,"tryCatchPattern":"try {\n    MyComponent c = injector.getInstance(MyComponent.class);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"mojo execution scope\")) {\n        // instance never seeded for this execution; request it via Mojo injection instead\n        throw new IllegalStateException(\"Resolve this dependency inside the mojo execution via field injection\", e);\n    }\n    throw e;\n}","preventionTips":["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()"],"tags":["maven","di","sisu","scope","mojo"],"backgroundTag":"di-scope-missing-binding","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}