2009-11-03 26 views
46

Chúng tôi có một dự án maven đa mô-đun sử dụng cấu hình xác định buildnumber-maven-plugin để tăng số bản dựng và sau đó kiểm tra nó vào kiểm soát nguồn.Thực hiện mục tiêu của plugin Maven trên mô-đun cha mẹ, nhưng không phải trên trẻ em

Nếu tôi xác định plugin trong tệp pom.xml gốc, nó thực thi cho tất cả các tệp con cũng được tạo.

Dưới đây là pom.xml mẹ tôi

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.webwars</groupId> 
    <artifactId>parent</artifactId> 
    <packaging>pom</packaging> 
    <properties> 
    <buildNumber.properties>${basedir}/../parent/buildNumber.properties</buildNumber.properties> 
    </properties> 
    <version>1.0-SNAPSHOT</version> 
    <name>Parent Project</name> 
    <profiles> 
    <profile> 
     <id>release</id> 
     <build> 
     <plugins> 
      <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <debug>false</debug> 
       <optimize>true</optimize> 
      </configuration> 
      </plugin> 
      <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>buildnumber-maven-plugin</artifactId> 
      <version>1.0-beta-3</version> 
      <executions> 
       <execution> 
       <phase>validate</phase> 
       <goals> 
        <goal>create</goal> 
       </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <buildNumberPropertiesFileLocation>${buildNumber.properties}</buildNumberPropertiesFileLocation> 
       <getRevisionOnlyOnce>true</getRevisionOnlyOnce> 
       <doCheck>false</doCheck> 
       <doUpdate>false</doUpdate> 
       <format>{0, number}</format> 
       <items> 
       <item>buildNumber</item> 
       </items> 
      </configuration> 
      </plugin> 
      <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-scm-plugin</artifactId> 
      <executions> 
       <execution> 
       <phase>install</phase> 
       <goals> 
        <goal>checkin</goal> 
       </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <basedir>${basedir}</basedir> 
       <includes>buildNumber.properties</includes> 
       <message>[Automated checkin] of ${basedir} Build version: ${major.version}.${minor.version}.${buildNumber}</message> 
       <developerConnectionUrl>...</developerConnectionUrl> 
      </configuration> 
      </plugin>   
     </plugins> 
     </build> 
    </profile> 
    </profiles> 

    <modules> 

    <module>../common</module> 
    <module>../data</module> 
    <module>../client</module> 
    <module>../webplatform</module> 
    </modules> 
... 
</project> 

Trả lời

78

Như ghi nhận trong phần Plugins của tham chiếu pom:

Ngoài tiêu chuẩn phối hợp của groupId: artifactId: phiên bản, có những yếu tố mà cấu hình các plugin hoặc điều này xây dựng tương tác với nó.

  • thừa hưởng: đúng hay sai, có hoặc không cấu hình plugin này nên áp dụng đối với POMs mà kế thừa từ thế này.

Vì vậy, chỉ cần thêm <inherited>false</inherited> để cấu hình buildnumber-maven-plugin để tránh thừa kế ở trẻ em POMs:

 <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>buildnumber-maven-plugin</artifactId> 
     <version>1.0-beta-3</version> 
     <inherited>false</inherited> 
     ... 
     </plugin> 
21

Bạn có thể thêm <inherited>false</inherited> để cấu hình plugin để tránh thừa kế ở trẻ em POMs:

 <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>buildnumber-maven-plugin</artifactId> 
     <version>1.0-beta-3</version> 
     <inherited>false</inherited> 
     ... 
     </plugin> 

Hoặc nếu plugin của bạn có nhiều lần thực thi, bạn có thể kiểm soát các lần thực thi nào được kế thừa và không bằng cách thêm thẻ kế thừa để cơ quan thi hành:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>parent-only</id> 
     <phase>initialize</phase> 
     <inherited>false</inherited> 
     <configuration> 
      <target> 
      <echo message="Echoed only by this module."/> 
      </target> 
     </configuration> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     </execution> 
     <execution> 
     <id>all-modules</id> 
     <phase>initialize</phase> 
     <inherited>true</inherited> <!-- Defaults to true, so you could leave this line out --> 
     <configuration> 
      <target> 
      <echo message="Echoed in this module and each child module."/> 
      </target> 
     </configuration> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 
4

Có một built-in tùy chọn maven: mvn --help ... -N,--non-recursive Do not recurse into sub-projects

1

Nếu plugin là tùy chỉnh và bạn có quyền truy cập vào mã MOJO plugin, bạn có thể đánh dấu plugin là aggregator; nếu hành vi dự kiến ​​được áp dụng cho tất cả các dự án mà plugin được sử dụng.

Như đã đề cập trong Mojo API Specification,

Flags Mojo này để chạy nó trong một mô-đun cách đa, ví dụ: tổng hợp các xây dựng với các thiết lập của dự án được liệt kê như mô-đun.

Ví dụ,

@Mojo(name = "createHF", inheritByDefault = false, aggregator = true) 
public class CreateHFMojo extends AbstractMojo { 

.. 

public void execute() throws MojoExecutionException, MojoFailureException { 
.... 
} 

.. 

} 

dụ chi tiết về github.

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