Maven 명령은 바운드 목표와 함께 수명주기 단계를 나열 하시겠습니까?

StackOverflow https://stackoverflow.com/questions/1709625

  •  19-09-2019
  •  | 
  •  

문제

나는 단지 Maven을 배우고 있습니다. 그래서 이것은 분명 할 수 있지만, 주어진 프로젝트의 각 Maven 라이프 사이클 단계와 관련된 목표를 쉽게 나열하는 방법을 찾을 수는 없습니다.

Maven 기본 수명주기 단계와 해당 기본 목표가 문서화되어 있음을 알았습니다. 여기. 지금까지의 이해는 각 pom.xml이 각 수명주기 단계에 추가 목표를 결합 할 수 있다는 것입니다.

그렇다면 주어진 프로젝트의 각 수명주기 단계에 대해 실행될 목표를 결정하기위한 MVN 명령이 있습니까? 그렇지 않다면, 나는 이것을 알아 내기 위해 각 새로운 Maven 프로젝트에 대해 pom.xml을 살펴 봐야한다고 생각합니까?

도움이 되었습니까?

해결책

mvn help:describe -Dcmd=compile (또는 기타 유효한 단계)

다른 팁

그만큼 buildplan-maven-plugin 목표가 단계에 어떻게 구속되는지 보여주는 훌륭한 도구입니다.

다음은 실행할 수있는 명령의 예입니다. 명령은 아직 설치되지 않은 경우 플러그인을 자동으로 다운로드하여 설치합니다.

그들이 실행할 순서별로 목표를 나열하십시오

> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list

PLUGIN                  | PHASE                  | ID                    | GOAL
--------------------------------------------------------------------------------------------
maven-enforcer-plugin   | validate               | default               | enforce
maven-dependency-plugin | process-sources        | default               | copy-dependencies
maven-resources-plugin  | process-resources      | default-resources     | resources
maven-compiler-plugin   | compile                | default-compile       | compile
maven-resources-plugin  | process-test-resources | default-testResources | testResources
maven-compiler-plugin   | test-compile           | default-testCompile   | testCompile
maven-surefire-plugin   | test                   | default-test          | test
maven-jar-plugin        | package                | default-jar           | jar
maven-assembly-plugin   | package                | make-assembly         | single
maven-install-plugin    | install                | default-install       | install
maven-deploy-plugin     | deploy                 | default-deploy        | deploy

단계별 그룹 목표

> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list-phase

validate -----------------------------------------------------------------
    + maven-enforcer-plugin   | default               | enforce
process-sources ----------------------------------------------------------
    + maven-dependency-plugin | default               | copy-dependencies
process-resources --------------------------------------------------------
    + maven-resources-plugin  | default-resources     | resources
compile ------------------------------------------------------------------
    + maven-compiler-plugin   | default-compile       | compile
process-test-resources ---------------------------------------------------
    + maven-resources-plugin  | default-testResources | testResources
test-compile -------------------------------------------------------------
    + maven-compiler-plugin   | default-testCompile   | testCompile
test ---------------------------------------------------------------------
    + maven-surefire-plugin   | default-test          | test
package ------------------------------------------------------------------
    + maven-jar-plugin        | default-jar           | jar
    + maven-assembly-plugin   | make-assembly         | single
install ------------------------------------------------------------------
    + maven-install-plugin    | default-install       | install
deploy -------------------------------------------------------------------
    + maven-deploy-plugin     | default-deploy        | deploy

플러그인 별 그룹 목표

> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list-plugin

maven-enforcer-plugin ---------------------------------------------------
    + validate               | default               | enforce
maven-dependency-plugin -------------------------------------------------
    + process-sources        | default               | copy-dependencies
maven-resources-plugin --------------------------------------------------
    + process-resources      | default-resources     | resources
    + process-test-resources | default-testResources | testResources
maven-compiler-plugin ---------------------------------------------------
    + compile                | default-compile       | compile
    + test-compile           | default-testCompile   | testCompile
maven-surefire-plugin ---------------------------------------------------
    + test                   | default-test          | test
maven-jar-plugin --------------------------------------------------------
    + package                | default-jar           | jar
maven-assembly-plugin ---------------------------------------------------
    + package                | make-assembly         | single
maven-install-plugin ----------------------------------------------------
    + install                | default-install       | install
maven-deploy-plugin -----------------------------------------------------
    + deploy                 | default-deploy        | deploy

메모

기본적으로 목표는 사용자가 호출하면 실행되는 작업을 검색합니다. mvn deploy. 다음과 같은 단계 clean 포함되지 않습니다. 검색에 여러 단계를 포함하려면 buildplan.tasks 재산:

> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list -Dbuildplan.tasks=clean,deploy

도움이되는 도구 중 하나입니다 mvn help:effective-pom 모든 변수로 POM을 인쇄하고 모든 부모 POM이 확장됩니다. 이것은 Maven이 보는 것을 이해하는 데 도움이됩니다. 그것으로부터, 모든 추가 목표를 찾는 것은 매우 간단합니다 (일반적으로 그다지 많지는 않습니다).

더 큰 문제는 암시 적 목표입니다 (즉, 플러그인이 수명주기의 일부 단계에 자동으로 연결될 때). 실제로 Maven을 실행하지 않고도 쉽게 볼 수있는 방법이 없습니다. 이것은 Maven 3에서 더 나아질 것입니다. 그때까지 Maven을 -X 디버그 출력과 현재 위상 및 실행되는 플러그인이 많이 인쇄됩니다.

Maven이 아니라 M2E를 사용하는 경우 Eclipse 플러그인에서 사용할 수있는 코드 블록을 사용하여 수행 할 수 있습니다.


final IMavenProjectRegistry projectRegistry = MavenPlugin.getMavenProjectRegistry();
    final IMavenProjectFacade facade = projectRegistry.getProject(project);
    projectRegistry.execute(facade, new ICallable<Void>() {
        public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
            MavenProject mavenProject = facade.getMavenProject(monitor);
            List<MojoExecution> mojoExecutions = ((MavenProjectFacade) facade).getMojoExecutions(monitor);
            LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(
                    mavenProject, mojoExecutions, facade.getResolverConfiguration().getLifecycleMappingId(),
                    monitor);
            Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mojoExecutionMapping = mappingResult
                    .getMojoExecutionMapping();

            Map<String, List<MojoExecutionKey>> phases = new LinkedHashMap<String, List<MojoExecutionKey>>();
            for (MojoExecutionKey execution : mojoExecutionMapping.keySet()) {
                List<MojoExecutionKey> executions = phases.get(execution.getLifecyclePhase());
                if (executions == null) {
                    executions = new ArrayList<MojoExecutionKey>();
                    phases.put(execution.getLifecyclePhase(), executions);

                    }
                    executions.add(execution);
                }

완전히 봐 원천.

이미 구현되었습니다 :

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

M2E의 목표 연관성을 단계와 계산하는 능력을 사용합니다. 나는 또한 Maven 수준에서 그것을 해결하려고 노력하고 있습니다.

차드의 대답을 스크립트에 넣었습니다 (따라서 정말 긴 플러그인 이름을 기억할 필요가 없습니다). 어디서나 사용할 수 있도록 ~/ bin/ 폴더에 넣으십시오.

#!/usr/bin/env bash
# Created based on https://stackoverflow.com/a/35610377/529256
debug=false

goal='list-phase'
build_plan='clean,deploy'
working_directories=""

for (( i=1; i<=$#; i++ )) do
    case ${!i} in

        -h|--help)
            programName=$( basename ${0} )
            echo "Lists the goals of mvn project(s) by phase in a table";
            echo
            echo "Usage:";
            echo "    ${programName} -d|--debug -g|--goal goal -b|--build_plan build_plan [*directory]";
            echo
            echo "           --goal  The goal for the buildplan-maven-plugin (default: $goal)"
            echo "                   (possible values: list, list-plugin, list-phase)"
            echo
            echo "     --build_plan  The value of the buildplan.tasks parameter (default: $build_plan)"
            echo "                   (examples: 'clean,install', 'deploy', 'install', etc...) "
            echo
            echo "     [*directory]  The directories (with pom.xml files) to run the command in"
            exit 0;
            ;;
        -d|--debug)
            debug=true;
            echo "debug = ${debug}";
            ;;
        -b|--build_plan)
            ((i++))
            build_plan="${!i}"
            ;;
        -g|--goal)
            ((i++))
            goal="${!i}"
            ;;
        *)
            working_directory="${!i}";
            if [ ! -e "${working_directory}" ]; then
                echo "'${working_directory}' doesn't exist";
                exit 1;
            fi;
            if [ -z "${working_directories}" ]; then
                working_directories="$working_directory"
            else
                working_directories="$working_directories ${!i}"
            fi;
            ;;
    esac;
done;

if [ -z "${working_directories}" ]; then
    working_directories="$PWD"
fi

if [ ${debug} = true ]; then
    echo "working_directories=$working_directories"
    echo "goal=$goal"
    echo "build_plan=$build_plan"
fi

for workingDirectory in ${working_directories}; do
    pushd ${workingDirectory} > /dev/null
    echo "cd $workingDirectory"
    echo "mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:${goal} -Dbuildplan.tasks=${build_plan}"
    mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:${goal} -Dbuildplan.tasks=${build_plan}
    popd > /dev/null
done;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top