2013-06-04 65 views
14

我試圖使用mvn help:effective-pom命令在示例應用程序上生成有效的pom。 http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom.html 在這篇文章中它說有效的pom是超級pom和應用程序pom之間的合併。有效-pom超級pom和應用程序POM之間的合併

但是,當我看着我的有效pom時,它包含了不包含在超級pom或有效pom中的元素。

是否有其他因素決定什麼進入有效的pom。

下面給出的是超級pom和應用程序pom,這兩個pom都沒有mavne-jar-plugin或maven-compiler-plugin,但是在我的effective-pom中,我可以在構建部分看到這些插件。那麼它是如何被添加的。

在此先感謝您的幫助是澄清這一問題

超級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 --> 

應用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

+1

我想你忘了添加有效的pom。 – Utku

回答

20

有效的POM由超級POM +應用程序POM(s)+ settings.xml內容+根據所選封裝類型(因此,基於應用程序POM中的一個元素)默認綁定到生命週期。您對maven-jar-pluginmaven-compiler-plugin提問有疑問?默認情況下這些綁定到生命週期,因爲您的應用程序POM指定jar包裝。

您可以在$YOUR_REPO_LOCATION\org\apache\maven\maven-core\3.0.x\maven-core-3.0.x.jar\META-INF\plexus\components.xmldocumentation中看到默認綁定。

+1

感謝您的回答,還有一個問題需要澄清,因此maven將在執行默認生命週期權期間採取有效措施,我對麼 ? – KItis

+3

Maven構造有效的pom,然後在執行任何命令的過程中使用它,無論是生命週期階段(例如'mvn install')還是特定目標(例如'mvn versions:display-dependency-updates')。 – user944849

+0

@ user944849順便說一句,我的'maven-core-3.0.3.jar'不在我的本地倉庫,而是在$(MAVEN_HOME)/ lib/maven-core-3.0.3.jar。這可能是什麼原因? – Utku

3

如果我沒有記錯,有效POM手段實際使用的POM。

將設置納入超級POM是其中的一部分。它還包括很多其他的東西,比如申請父母POM,申請個人資料,替換屬性等。

我認爲如果你能給出一些你認爲來自哪裏的設置,那麼會更好,所以我們可以確定它們來自哪裏。

+0

我已經更新了超級POM,應用程序pom以及有效pom中的新功能的問題 – KItis