有效的POM是超级POM和应用程序POM之间的合并吗?

15

我尝试使用mvn help:effective-pom命令在示例应用程序上生成有效的pom。

http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom.html

在这篇文章中,它说effective pom是超级pom和应用程序pom之间的合并。

但是,当我查看我的effective-pom时,它包含了既不包括在超级pom中也不包括在应用程序pom中的元素。

是否有其他因素决定了哪些内容会添加到effective 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


2
我猜你忘记添加有效的pom了。 - Utku
3个回答

23

有效的 POM 由 Super 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.xml文档中查看默认的绑定。


1
谢谢您的回答,还有一个问题需要澄清,那么在执行默认生命周期时,Maven会对有效的POM文件进行操作,我理解得对吗? - KItis
3
Maven 构建有效的 POM,然后在执行任何命令时使用它,无论是生命周期阶段(例如 mvn install)还是特定目标(例如 mvn versions:display-dependency-updates)。 - user944849
顺便说一下,我的 maven-core-3.0.3.jar 不在本地仓库,而是在 $(MAVEN_HOME)/lib/maven-core-3.0.3.jar。这可能是什么原因呢? - Utku
我碰巧在我的本地存储库中找到了这个工件,所以我停止在其他地方寻找。你在应用程序安装中找到了它。如果版本相同,应该是相同的信息。 - user944849

3

如果我没记错的话,“有效的 POM” 意味着实际要使用的 POM。

在超级 POM 中合并设置也是其中的一部分。它还包括很多其他内容,比如应用父 POM、应用配置文件、替换属性等等。

我认为如果您能提供一些您认为突然冒出来的设置片段,那么我们就可以确定它们来自哪里,这会更好。


我已更新问题与 Super POM、应用程序 pom 和有效 POM 中的新功能。 - KItis

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接