【问题标题】:How does maven default life cycle get executed on maven projectmaven默认生命周期如何在maven项目上执行
【发布时间】:2013-05-28 15:20:22
【问题描述】:

我在 Maven 的上下文中有一个非常简单的问题。在 Maven 世界中,它说关于我的项目的所有内容都在项目对象模型中定义。

所以,当我将<packaging> 元素放在我的项目对象模型中作为战争等时,maven 会将适当的目标应用于 maven 的默认生命周期。但要使其工作,我必须定义项目 maven-war -plugin 在我的项目对象模型的构建部分中。但是当我检查我的 pom 和 super pom 时,它没有包含 maven-war-plugin。我正在使用 maven 3.0.5 并且超级 pom 位于内部

\maven-model-builder-3.0.5\org\apache\maven\model

以下是超级 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 -->

【问题讨论】:

    标签: maven maven-3 pom.xml parent-pom


    【解决方案1】:

    看看default-bindings.xml,尤其是&lt;role-hint&gt;war&lt;/role-hint&gt;的定义:

    <component>
      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
      <role-hint>war</role-hint>
      <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
      <configuration>
      ...
              <package>
                org.apache.maven.plugins:maven-war-plugin:2.2:war
              </package>
    

    这通过引用特定于战争的插件来定义此包装类型的package 阶段将运行的目标。

    这由Built-in Lifecycle Bindings 中的Introduction to the Build Lifecycle 覆盖。

    【讨论】:

    • 感谢您的回答。我还有一个问题,当我查看 super POM 时,我看不到 maven-archetype-webapp 插件,但是当我查看有效 pom 时,我可以在构建部分看到这个插件。如果不在 supper pom 或 child pom 中,它如何被包含到有效 pom 中
    • 如果它在那里,它是由 pom 本身、父 pom、超级 pom 或包装定义引入的。您可以尝试修改您的 pom 并再次运行 effective-pom 以查看发生了什么变化以及带来了什么。
    • 我在想 pom 是由父 pom、supper pom 和 pom 它自己创建的,根据您的回答,它可以通过我选择的包装创建。那是对的吗。但我没有在文档中找到这一点
    猜你喜欢
    • 1970-01-01
    • 2011-09-25
    • 2012-04-12
    • 2016-08-02
    • 1970-01-01
    • 2014-04-18
    • 2014-12-25
    • 2013-02-21
    • 1970-01-01
    相关资源
    最近更新 更多