2012-11-06 3 views
9

부모 pom의 pluginManagement에서 플러그인에 대해 다른 실행을 정의한 다음 하위 poms의 단계에 특정 실행을 바인딩하려고합니다. 사용되는 플러그인 및 pluginManagement 섹션의 위치에 따라 일관되지 않은 동작이 나타납니다.Maven 플러그인 단계의 기본 바인딩을 재정의하는 방법

이 첫 번째 예에서 pluginManagement는 상위 pom에 있으며 컴파일러 플러그인의 경우 2 회 실행과 antrun 플러그인의 경우 2 회 실행을 정의합니다.

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<name>master-pom</name> 
<modelVersion>4.0.0</modelVersion> 
<groupId>plugin.test</groupId> 
<artifactId>master-pom</artifactId> 
<packaging>pom</packaging> 
<version>1.0.0-SNAPSHOT</version> 
<build> 
    <pluginManagement> 
     <plugins>    
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>execution-1</id> 
         <phase>none</phase> 
         <goals> 
          <goal>compile</goal> 
         </goals> 
         <configuration> 
          <source>1.6</source> 
          <target>1.6</target> 
          <includes> 
           <include>**/*</include> 
          </includes> 
         </configuration> 
        </execution> 
        <execution> 
         <id>execution-2</id> 
         <phase>none</phase> 
         <goals> 
          <goal>compile</goal> 
         </goals> 
         <configuration> 
          <source>1.5</source> 
          <target>1.5</target> 
          <includes> 
           <include>**/*</include> 
          </includes> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.7</version> 
       <executions> 
        <execution> 
         <id>execution-1</id> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <configuration> 
          <target> 
           <echo message="execution 1"/> 
          </target> 
         </configuration> 
        </execution> 
        <execution> 
         <id>execution-2</id> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <configuration> 
          <target> 
           <echo message="execution 1"/> 
          </target> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 
    </pluginManagement> 
</build> 

그리고 자식 치어 :

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<name>build</name> 
<modelVersion>4.0.0</modelVersion> 
<groupId>plugin.test</groupId> 
<artifactId>build</artifactId> 
<version>1.0.0-SNAPSHOT</version> 
<packaging>pom</packaging> 
<parent> 
    <groupId>plugin.test</groupId> 
    <artifactId>master-pom</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <relativePath>./master-pom.xml</relativePath> 
</parent> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>execution-1</id> 
        <phase>generate-sources</phase> 
       </execution> 
      </executions> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>execution-1</id> 
        <phase>generate-sources</phase> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

자식 치어에 '새로 설치하는 MVN'를 실행 컴파일러 플러그인을 모두 실행 만 1 실행을 실행 antrun 플러그인의 첫 번째 실행 만이 단계에 바인딩되었지만.

지금 자식 치어에 pluginManagement 이동 :

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<name>build</name> 
<modelVersion>4.0.0</modelVersion> 
<groupId>plugin.test</groupId> 
<artifactId>build</artifactId> 
<version>1.0.0-SNAPSHOT</version> 
<packaging>pom</packaging> 
<build> 
    <pluginManagement> 
     <plugins>    
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>execution-1</id> 
         <phase>none</phase> 
         <goals> 
          <goal>compile</goal> 
         </goals> 
         <configuration> 
          <source>1.6</source> 
          <target>1.6</target> 
          <includes> 
           <include>**/*</include> 
          </includes> 
         </configuration> 
        </execution> 
        <execution> 
         <id>execution-2</id> 
         <phase>none</phase> 
         <goals> 
          <goal>compile</goal> 
         </goals> 
         <configuration> 
          <source>1.5</source> 
          <target>1.5</target> 
          <includes> 
           <include>**/*</include> 
          </includes> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.7</version> 
       <executions> 
        <execution> 
         <id>execution-1</id> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <configuration> 
          <target> 
           <echo message="execution 1"/> 
          </target> 
         </configuration> 
        </execution> 
        <execution> 
         <id>execution-2</id> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <configuration> 
          <target> 
           <echo message="execution 2"/> 
          </target> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 
    </pluginManagement> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>execution-1</id> 
        <phase>generate-sources</phase> 
       </execution> 
      </executions> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>execution-1</id> 
        <phase>generate-sources</phase> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

이 치어 각 플러그인 만 1 실행을 실행하고 원하는 동작을 제공합니다. 컴파일러 플러그인 (및 대부분의 플러그인)은 pluginManagement가 동일한 pom에 있고 모든 실행이 phase = none에 바인딩되어있는 경우에만 올바르게 작동합니다 (이는 실행을 기본 단계에 바인딩하기 때문일 수 있음). antrun 플러그인은 어떤 경우에도 올바르게 작동합니다.

부모 pom에서 pluginManagement 섹션을 사용하면서 자식 poms에서 phase = none으로 원하지 않는 실행을 구체적으로 바인딩하지 않고 어떻게이 작업을 수행 할 수 있습니까? Maven의 버그입니까? 아니면이 동작이 어떻게 든 정당화되어 있습니까? 나는 이것을 Maven 3.0.4와 Maven 2.2.1에서 같은 결과로 시도했다.

+0

첫 번째 설정을 시도했지만 컴파일러와 antrun 플러그인 모두'execution-1' 만있었습니다. 컴파일러 플러그인이'execution-1'과'execution-2'를 모두 실행했다고합니다. 내가 말했듯이, 그것은 나에게 일어나지 않았다. – maba

+0

당신 말이 맞아요. 트릭은 기본적으로 바인드하는 플러그인에 phase = none을 추가하는 것입니다. 추가 한 후에 부모 POM을 로컬 저장소에 배포하지 않았으므로 이전 부모를 사용하려고했습니다. –

답변

4

제공된 예제가 올바르게 작동합니다. 수정본을 포함시킨 후 부모를 재배치하지 않았습니다.

대부분의 플러그인은 실행을 기본 단계로 바인딩합니다. 따라서 플러그인 실행 중 하나가 실행되면 모든 언 바운드 실행이 기본 단계에 바인딩되고 실행됩니다.

이 문제를 방지하려면 상위 pom의 pluginManagement 섹션에있는 모든 플러그인 실행을 phase = none에 바인딩해야합니다 (제공된 예제 참조). 이 방법은 자식 poms에서 단계가 명시 적으로 무시되지 않으면 실행되지 않습니다.

관련 문제