2013-02-01 31 views
12

Tôi đang cố viết pom mẹ và tôi đã xác định plugin, nhưng tôi cần thay đổi cấu hình cho tất cả các phiên bản được kế thừa. Vì vậy, tôi có thể đặt một số cấu hình trong định nghĩa <pluginManagement> và tôi có thể ghi đè nó trong <plugin>, nhưng làm cách nào để đưa các con trở về mặc định cho phiên bản <pluginManagement>?Đấu tranh với thừa kế cấu hình của cha mẹ/con Maven

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-checkstyle-plugin</artifactId> 
       <version>2.9.1</version> 
       <executions...> 
       <configuration> 
        <configLocation> 
         (used by all children) 
        </configLocation> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-checkstyle-plugin</artifactId> 
      <configuration> 
       <configLocation> 
        (unique to the parent) 
       </configLocation> 
      </configuration> 
     </plugin> 
    </plugins> 
<build> 

Vì vậy, điều xảy ra là trẻ tiếp tục hiển thị cấu hình của cha mẹ.

Trả lời

12

Ok, tôi nghĩ tôi có nó Câu trả lời, trong trường hợp của tôi, liên quan đến những gì mà bạn chỉ định - tôi đã làm cần thẻ Tuy nhiên, giải pháp là trong thẻ;.. bằng cách gắn nó vào một phi Điều này tôi biết, những gì tôi phát hiện ra là nó phải khớp với thứ tự để nó ghi đè lên. Vì vậy, cấu hình không bao giờ được phân tích cú pháp và không quan trọng.

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <!-- Main declaration of the plugin --> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-checkstyle-plugin</artifactId> 
       <version>2.9.1</version> 
       <executions> 
        <execution> 
         <!--This must be named--> 
         <id>checkstyle</id> 
         <phase>compile</phase> 
         <goals> 
          <goal>check</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration...> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
    <plugins> 
     <plugin> 
      <!-- Uses the default config --> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-checkstyle-plugin</artifactId> 
      <inherited>false</inherited> 
      <executions> 
       <execution> 
        <!--This matches and thus overrides--> 
        <id>checkstyle</id> 
        <phase>none</phase> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
7

Bạn rõ ràng có thể chỉ định trong pom cha mẹ của bạn rằng các plugin không nên được thừa hưởng:

<build> 
    <pluginManagement> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-checkstyle-plugin</artifactId> 
      <version>2.9.1</version> 
      <executions...> 
      <configuration> 
       <configLocation> 
        (used by all children) 
       </configLocation> 
      </configuration> 
     </plugin> 
    </plugins> 
</pluginManagement> 
<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-checkstyle-plugin</artifactId> 
     <inherited>false</inherited>      <!-- Add this line --> 
     <configuration> 
      <configLocation> 
       (unique to the parent) 
      </configLocation> 
     </configuration> 
    </plugin> 
    </plugins> 
<build> 

Và trong pom con bạn, bạn cần phải xác định các plugin (cấu hình sau đó sẽ đến từ các yếu tố <pluginManagement> mẹ .

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-checkstyle-plugin</artifactId> 
    </plugin> 
    </plugins> 
<build> 
+1

Vâng, vâng, đó là chính xác. Tuy nhiên, nó có nghĩa là chỉ định plugin một cách rõ ràng trong * mọi * con. Tôi thích ý tưởng rằng tôi có thể kế thừa từ cha mẹ một cách tự động. –

Các vấn đề liên quan