pom reference 筆記 二

Inheritance 繼承

<packaging>pom</packaging>:對於父項目或聚合(多模塊)項目,<packageing>必須爲pom
父pom中的以下元素可以被子項目繼承:
dependencies developers and contributors plugin lists reports lists plugin executions with matching ids plugin configuration

 

 

 

 

典型的父pom和子pom如下:

 

 

 

 

和java中所有類的父類都爲Object類一樣,所有的pom多有最終的super pom,只是我們一直不知道而已,該pom內容可在apache上查閱

 

 

 

除了子類繼承父pom的頂級元素,父pom也可以定義頂級元素影響子pom,其中的典型就是依賴管理:

<dependencyManagement><?dependencyManagement>,看看文檔中對其作用的解釋:


dependencyManagement: is used by POMs to help manage dependency information across all of its children. If the my-parent project uses dependencyManagement to define a dependency on junit:junit:4.0, then POMs inheriting from this one can set their dependency giving the groupId=junit and artifactId=junit only, then Maven will fill in the version set by the parent. The benefits of this method are obvious. Dependency details can be set in one central location, which will propagate to all inheriting POMs. In addition, the version and scope of artifacts which are incorporated from transitive dependencies may also be controlled by specifying them in a dependency management section.

 

 

 

 (or Multi-Module)

 

A project with modules is known as a multimodule, or aggregator project. Modules are projects that this POM lists, and are executed as a group. An pom packaged project may aggregate the build of a set of projects by listing them as modules, which are relative directories to those projects.

You do not need to consider the inter-module dependencies yourself when listing the modules, i.e. the ordering of the modules given by the POM is not important. Maven will topologically sort the modules such that dependencies are always build before dependent modules.

 

Properties

Properties are the last required piece in understanding POM basics. Maven properties are value placeholder, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. They come in five different styles:

  1. env.X: Prefixing a variable with "env." will return the shell's environment variable. For example, ${env.PATH} contains the PATH environment variable. Note: While environment variables themselves are case-insensitive on Windows, lookup of properties is case-sensitive. In other words, while the Windows shell returns the same value for %PATH% and %Path%, Maven distinguishes between ${env.PATH} and ${env.Path}. As of Maven 2.1.0, the names of environment variables are normalized to all upper-case for the sake of reliability.
  2. project.x: A dot (.) notated path in the POM will contain the corresponding element's value. For example: <project><version>1.0</version></project> is accessible via ${project.version}.
  3. settings.x: A dot (.) notated path in the settings.xml will contain the corresponding element's value. For example: <settings><offline>false</offline></settings> is accessible via ${settings.offline}.
  4. Java System Properties: All properties accessible via java.lang.System.getProperties() are available as POM properties, such as ${java.home}.
  5. x: Set within a <properties /> element. The value may be used as ${someVar}

到這裏,pom.xml文件的基礎部分就簡單看完了,接下來看高級部分

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章