Maven command to list lifecycle phases along with bound goals?

前端 未结 5 1682
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 07:24

I\'m just learning Maven, and so this might be obvious, but I can\'t find an easy way to list the goals associated for each maven lifecycle phase for a given project.

5条回答
  •  盖世英雄少女心
    2020-12-07 07:48

    If not with Maven but using m2e you can do it using the code block that you can use in a Eclipse plugin:


    final IMavenProjectRegistry projectRegistry = MavenPlugin.getMavenProjectRegistry();
        final IMavenProjectFacade facade = projectRegistry.getProject(project);
        projectRegistry.execute(facade, new ICallable() {
            public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
                MavenProject mavenProject = facade.getMavenProject(monitor);
                List mojoExecutions = ((MavenProjectFacade) facade).getMojoExecutions(monitor);
                LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(
                        mavenProject, mojoExecutions, facade.getResolverConfiguration().getLifecycleMappingId(),
                        monitor);
                Map> mojoExecutionMapping = mappingResult
                        .getMojoExecutionMapping();
    
                Map> phases = new LinkedHashMap>();
                for (MojoExecutionKey execution : mojoExecutionMapping.keySet()) {
                    List executions = phases.get(execution.getLifecyclePhase());
                    if (executions == null) {
                        executions = new ArrayList();
                        phases.put(execution.getLifecyclePhase(), executions);
    
                        }
                        executions.add(execution);
                    }
    

    Look at full source.

    Already implemented in:

    http://marketplace.eclipse.org/content/phases-and-goals

    It makes use of m2e's ability to compute the association of goals with phases. I am also trying to solve it at maven level.

提交回复
热议问题