{"record":{"id":"23ca25b29506a13a","repo":"apache/maven","slug":"goal-requires-a-project-to-execute-but-there-is-no","errorCode":null,"errorMessage":"Goal requires a project to execute but there is no POM in this directory ({}). Please verify you invoked Maven from the correct directory.","messagePattern":"Goal requires a project to execute but there is no POM in this directory \\((.+?)\\)\\. Please verify you invoked Maven from the correct directory\\.","errorType":"exception","errorClass":"LifecycleExecutionException","httpStatus":null,"severity":"error","filePath":"impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java","lineNumber":198,"sourceCode":"        phaseRecorder.observeExecution(mojoExecution);\n    }\n\n    private void execute(MavenSession session, MojoExecution mojoExecution, DependencyContext dependencyContext)\n            throws LifecycleExecutionException {\n        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();\n\n        try {\n            mavenPluginManager.checkPrerequisites(mojoDescriptor.getPluginDescriptor());\n        } catch (PluginIncompatibleException e) {\n            throw new LifecycleExecutionException(messageBuilderFactory, mojoExecution, session.getCurrentProject(), e);\n        }\n\n        if (mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent()) {\n            Throwable cause = new MissingProjectException(\n                    \"Goal requires a project to execute\" + \" but there is no POM in this directory (\"\n                            + session.getExecutionRootDirectory() + \").\"\n                            + \" Please verify you invoked Maven from the correct directory.\");\n            throw new LifecycleExecutionException(messageBuilderFactory, mojoExecution, null, cause);\n        }\n\n        if (mojoDescriptor.isOnlineRequired() && session.isOffline()) {\n            if (MojoExecution.Source.CLI.equals(mojoExecution.getSource())) {\n                Throwable cause = new IllegalStateException(\n                        \"Goal requires online mode for execution\" + \" but Maven is currently offline.\");\n                throw new LifecycleExecutionException(\n                        messageBuilderFactory, mojoExecution, session.getCurrentProject(), cause);\n            } else {\n                eventCatapult.fire(ExecutionEvent.Type.MojoSkipped, session, mojoExecution);\n\n                return;\n            }\n        }\n\n        doExecute(session, mojoExecution, dependencyContext);\n    }\n","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java#L180-L216","documentation":"MojoExecutor.execute() checks the mojo descriptor before running: if the plugin goal declares requiresProject=true (the default for most mojos) but the session has no project present, it throws LifecycleExecutionException wrapping a MissingProjectException naming the execution root directory. Unlike the starter-level check (DefaultLifecycleStarter), this one fires per-mojo, covering cases where the task parsed as a goal but the goal itself demands a project.","triggerScenarios":"Invoking a requiresProject=true goal (most plugin goals, e.g. compiler:compile) with no pom.xml in the execution root — for example 'mvn compiler:compile' in an empty directory, or with -f pointing to a non-POM; also programmatic MojoExecution where the session request was built with isProjectPresent=false.","commonSituations":"Running one-off plugin goals outside a project; shell scripts starting in the wrong directory; embedders creating a project-less session but invoking standard mojos; IDE actions on a closed/deleted project.","solutions":["Run the goal from a directory containing pom.xml, or pass -f /path/to/pom.xml","Pick a projectless-capable variant/goal (goals explicitly marked requiresProject=false, like archetype:generate) if you truly have no POM","For embedders, ensure MavenExecutionRequest is configured with a project (request.setPom/file present) before executing such mojos","Guard scripts by testing [ -f pom.xml ] before invoking project-bound goals"],"exampleFix":"# before\ncd /tmp && mvn dependency:resolve-goals   # goal requires a project\n\n# after\ncd /path/to/project && mvn compiler:compile\n# or: mvn -f /path/to/project/pom.xml compiler:compile","handlingStrategy":"validation","validationCode":"// check the mojo's requirement before executing\nif (mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent()) {\n    throw new MissingProjectException(\"Goal \" + mojoDescriptor.getGoal() + \" needs a project; supply pom.xml\");\n}","typeGuard":null,"tryCatchPattern":"catch (LifecycleExecutionException e) {\n    if (e.getCause() instanceof MissingProjectException) {\n        // rerun from the project directory or with -f pointing at the POM\n    }\n}","preventionTips":["Run project-bound goals from the module directory or with -f","Embedders: set the POM on MavenExecutionRequest so isProjectPresent() is true","Prefer explicitly projectless goals for one-off scaffolding tasks"],"tags":["maven","mojo","requires-project","missing-pom","execution"],"backgroundTag":"no-pom-in-directory","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}