{"record":{"id":"e116343c5cc5cddd","repo":"apache/maven","slug":"illegal-call-to-phase-the-main-phase-wi","errorCode":null,"errorMessage":"Illegal call to phase '{}'. The main phase '{}' will be used instead.","messagePattern":"Illegal call to phase '(.+?)'\\. The main phase '(.+?)' will be used instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java","lineNumber":106,"sourceCode":"        }\n\n        return calculateTaskSegments(session, tasks);\n    }\n\n    @Override\n    public List<TaskSegment> calculateTaskSegments(MavenSession session, List<String> tasks)\n            throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,\n                    MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,\n                    PluginVersionResolutionException {\n        List<TaskSegment> taskSegments = new ArrayList<>(tasks.size());\n\n        TaskSegment currentSegment = null;\n\n        for (String task : tasks) {\n            if (isBeforeOrAfterPhase(task)) {\n                String prevTask = task;\n                task = PhaseId.of(task).phase();\n                LOGGER.warn(\"Illegal call to phase '{}'. The main phase '{}' will be used instead.\", prevTask, task);\n            }\n            if (isGoalSpecification(task)) {\n                // \"pluginPrefix[:version]:goal\" or \"groupId:artifactId[:version]:goal\"\n\n                lifecyclePluginResolver.resolveMissingPluginVersions(session.getTopLevelProject(), session);\n\n                MojoDescriptor mojoDescriptor =\n                        mojoDescriptorCreator.getMojoDescriptor(task, session, session.getTopLevelProject());\n\n                boolean aggregating = mojoDescriptor.isAggregator() || !mojoDescriptor.isProjectRequired();\n\n                if (currentSegment == null || currentSegment.isAggregating() != aggregating) {\n                    currentSegment = new TaskSegment(aggregating);\n                    taskSegments.add(currentSegment);\n                }\n\n                currentSegment.getTasks().add(new GoalTask(task));\n            } else {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java#L88-L124","documentation":"Maven 4 decorates every lifecycle phase with implicit 'before:<phase>' and 'after:<phase>' sub-phases (Lifecycle.BEFORE/Lifecycle.AFTER prefixes). calculateTaskSegments detects a task string starting with those prefixes, strips it down to the main phase via PhaseId.of(task).phase(), warns that the call was illegal, and schedules the main phase - so 'mvn before:compile' builds up to and including compile, not just the pre-step.","triggerScenarios":"Passing before:<phase> or after:<phase> as a goal on the command line or via MavenSession goals programmatically; the before/after sub-phases are internal stepping stones, not directly invocable tasks.","commonSituations":"Users experimenting with Maven 4 phase syntax; scripts generated from phase listings that include the synthetic before:/after: entries; IDE task templates listing all phases.","solutions":["Invoke the plain phase instead: mvn compile rather than mvn before:compile / mvn after:compile","If you only want pre/post hooks, bind your plugin executions to the standard phases in the POM","For programmatic invocations, sanitize the task list by stripping before:/after: prefixes before calling Maven"],"exampleFix":"# before\nmvn after:package     # warns; runs 'package' itself\nmvn before:compile    # warns; runs 'compile' itself\n# after\nmvn package\nmvn compile","handlingStrategy":"validation","validationCode":"// programmatic invocation: strip illegal before:/after: prefixes before calling Maven\nList<String> sanitized = tasks.stream()\n        .map(t -> t.startsWith(\"before:\") || t.startsWith(\"after:\") ? t.substring(t.indexOf(':') + 1) : t)\n        .distinct()\n        .collect(Collectors.toList());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Invoke plain phase names (mvn compile, mvn package) - before:/after: sub-phases are internal","When listing phases for users, filter out the before:/after: variants","Treat this warning as a sign a script generated the wrong task names"],"tags":["lifecycle","phase-invocation","maven-4","task-segments"],"backgroundTag":"invalid-lifecycle-phase-invocation","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}