2013-06-04 33 views
14

Tôi đã cố gắng để tạo ra pom hiệu quả trên ứng dụng mẫu bằng cách sử dụng lệnh mvn help: effect-pom. http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom.html tại bài viết này nói rằng pom hiệu quả là sự hợp nhất giữa pom siêu và ứng dụng pom.Là hiệu quả-pom một sự hợp nhất giữa siêu pom và ứng dụng POM

Nhưng, khi tôi nhìn vào hiệu quả của tôi-pom, nó có chứa các yếu tố không được bao gồm trong một trong hai siêu pom hoặc pom hiệu quả.

Có yếu tố nào khác quyết định những gì có hiệu quả không.

Đưa ra dưới đây là pom siêu và pom ứng dụng, Cả hai pom này không có plugin mavne-jar-plugin hoặc maven-compiler-plugin, nhưng trong hiệu quả của tôi-pom, tôi có thể thấy các plugin trong phần xây dựng. Vậy làm thế nào để nó được thêm vào.

Cảm ơn trước sự giúp đỡ nào làm rõ vấn đề này

Siêu POM

<!-- 
Licensed to the Apache Software Foundation (ASF) under one 
or more contributor license agreements. See the NOTICE file 
distributed with this work for additional information 
regarding copyright ownership. The ASF licenses this file 
to you under the Apache License, Version 2.0 (the 
"License"); you may not use this file except in compliance 
with the License. You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, 
software distributed under the License is distributed on an 
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express or implied. See the License for the 
specific language governing permissions and limitations 
under the License. 
--> 

<!-- START SNIPPET: superpom --> 
<project> 
    <modelVersion>4.0.0</modelVersion> 

    <repositories> 
    <repository> 
     <id>central</id> 
     <name>Central Repository</name> 
     <url>http://repo.maven.apache.org/maven2</url> 
     <layout>default</layout> 
     <snapshots> 
     <enabled>false</enabled> 
     </snapshots> 
    </repository> 
    </repositories> 

    <pluginRepositories> 
    <pluginRepository> 
     <id>central</id> 
     <name>Central Repository</name> 
     <url>http://repo.maven.apache.org/maven2</url> 
     <layout>default</layout> 
     <snapshots> 
     <enabled>false</enabled> 
     </snapshots> 
     <releases> 
     <updatePolicy>never</updatePolicy> 
     </releases> 
    </pluginRepository> 
    </pluginRepositories> 

    <build> 
    <directory>${project.basedir}/target</directory> 
    <outputDirectory>${project.build.directory}/classes</outputDirectory> 
    <finalName>${project.artifactId}-${project.version}</finalName> 
    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory> 
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> 
    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory> 
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory> 
    <resources> 
     <resource> 
     <directory>${project.basedir}/src/main/resources</directory> 
     </resource> 
    </resources> 
    <testResources> 
     <testResource> 
     <directory>${project.basedir}/src/test/resources</directory> 
     </testResource> 
    </testResources> 
    <pluginManagement> 
     <!-- NOTE: These plugins will be removed from future versions of the super POM --> 
     <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) --> 
     <plugins> 
     <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <version>1.3</version> 
     </plugin> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2-beta-5</version> 
     </plugin> 
     <plugin> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.1</version> 
     </plugin> 
     <plugin> 
      <artifactId>maven-release-plugin</artifactId> 
      <version>2.0</version> 
     </plugin> 
     </plugins> 
    </pluginManagement> 
    </build> 

    <reporting> 
    <outputDirectory>${project.build.directory}/site</outputDirectory> 
    </reporting> 

    <profiles> 
    <!-- NOTE: The release profile will be removed from future versions of the super POM --> 
    <profile> 
     <id>release-profile</id> 

     <activation> 
     <property> 
      <name>performRelease</name> 
      <value>true</value> 
     </property> 
     </activation> 

     <build> 
     <plugins> 
      <plugin> 
      <inherited>true</inherited> 
      <artifactId>maven-source-plugin</artifactId> 
      <executions> 
       <execution> 
       <id>attach-sources</id> 
       <goals> 
        <goal>jar</goal> 
       </goals> 
       </execution> 
      </executions> 
      </plugin> 
      <plugin> 
      <inherited>true</inherited> 
      <artifactId>maven-javadoc-plugin</artifactId> 
      <executions> 
       <execution> 
       <id>attach-javadocs</id> 
       <goals> 
        <goal>jar</goal> 
       </goals> 
       </execution> 
      </executions> 
      </plugin> 
      <plugin> 
      <inherited>true</inherited> 
      <artifactId>maven-deploy-plugin</artifactId> 
      <configuration> 
       <updateReleaseInfo>true</updateReleaseInfo> 
      </configuration> 
      </plugin> 
     </plugins> 
     </build> 
    </profile> 
    </profiles> 

</project> 
<!-- END SNIPPET: superpom --> 

Application POM

<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.sonatype.mavenbook.ch08</groupId> 
    <artifactId>simplest-project</artifactId> 
    <packaging>jar</packaging> 
    <version>1</version> 
</project> 

pom hiệu quả

+1

Tôi đoán bạn quên thêm pom hiệu quả. – Utku

Trả lời

20

POM hiệu quả bao gồm nội dung POM + ứng dụng POM + nội dung settings.xml + bổ sung liên kết với vòng đời theo mặc định dựa trên loại đóng gói được chọn (do đó, dựa trên một phần tử trong ứng dụng POM).

Bạn đã hỏi về maven-jar-pluginmaven-compiler-plugin. Đây là những ràng buộc với vòng đời theo mặc định vì ứng dụng của bạn POM chỉ định jar bao bì.

Bạn có thể xem các liên kết mặc định trong $YOUR_REPO_LOCATION\org\apache\maven\maven-core\3.0.x\maven-core-3.0.x.jar\META-INF\plexus\components.xml hoặc trong documentation.

+1

Cảm ơn bạn đã trả lời câu hỏi này, Một câu hỏi nữa cần làm rõ, Vì vậy, maven sẽ hoạt động trên pom hiệu quả trong thời gian thực hiện vòng đời mặc định, Tôi có đúng không? – KItis

+3

Maven xây dựng pom hiệu quả, sau đó sử dụng nó trong khi thực hiện bất kỳ lệnh nào, cho dù giai đoạn vòng đời (ví dụ 'mvn install') hoặc mục tiêu cụ thể (ví dụ:' mvn versions: display-dependency-updates'). – user944849

+0

@ user944849 Nhân tiện, 'maven-core-3.0.3.jar' của tôi không có ở kho lưu trữ cục bộ của tôi, nhưng tại' $ (MAVEN_HOME)/lib/maven-core-3.0.3.jar'. Điều gì có thể là lý do cho điều này? – Utku

3

Nếu tôi nhớ không lầm thì có nghĩa là POM hiệu quả POM thực tế được sử dụng.

Kết hợp cài đặt trong siêu POM là một phần của nó. Nó cũng bao gồm rất nhiều thứ khác, như áp dụng cha mẹ POM, áp dụng hồ sơ, thay thế tài sản, và vv

Tôi nghĩ sẽ tốt hơn nếu bạn có thể đưa ra một số cài đặt mà bạn cho là không có ở đâu chúng ta có thể xác định chúng đến từ đâu.

+0

Tôi đã cập nhật câu hỏi với Super POM, pom ứng dụng và các tính năng mới trong hiệu quả-pom – KItis