Maven 模型生成器

有效的模型构建器,具有配置文件激活、继承、插值、...

主要组件是ModelBuilder ( javadoc , source ),其DefaultModelBuilder实现 ( javadoc , source ) 用于管理步骤序列。

该序列分为 2 个阶段,具有可选的插件处理:

  • 阶段1
    • 原始模型验证:ModelValidator ( javadoc ),及其DefaultModelValidator实现 ( source )
    • 配置文件激活:查看可用的激活器。请注意,模型插值尚未发生,基于文件的激活插值仅限于${basedir}(从 Maven 3 开始)、系统属性和请求属性
    • 模型规范化:ModelNormalizer ( javadoc ),及其DefaultModelNormalizer实现 ( source )
    • 轮廓注入
    • 父级分辨率直到超级 pom
    • 继承程序集:InheritanceAssembler ( javadoc ),及其DefaultInheritanceAssembler实现 ( source )
    • 模型插值(见下文)
    • url 规范化:UrlNormalizer ( javadoc ),及其DefaultUrlNormalizer实现 ( source )
  • 阶段2
    • 模型路径翻译:ModelPathTranslator ( javadoc ),及其DefaultModelPathTranslator实现 ( source )
    • 插件管理注入
    • (可选)生命周期绑定注入
    • dependency management import (for dependencies of type pom in the <dependencyManagement> section)
    • dependency management injection
    • (optional) reports configuration
    • (optional) reports conversion to decoupled site plugin
    • (optional) plugins configuration
    • effective model validation: ModelValidator (javadoc), with its DefaultModelValidator implementation (source)

Model Interpolation

Model Interpolation consists in replacing ${...} with calculated value. It is done in StringSearchModelInterpolator (javadoc, source).

Notice that model interpolation happens after profile activation, then profile activation doesn't benefit from every values: interpolation for file-based activation is limited to ${basedir} (which was introduced in Maven 3 and is not deprecated in this context), System properties and request properties.

Values are evaluated in sequence from different syntaxes:

value evaluation result common examples
project.* 
pom.* (deprecated
* (deprecated)
POM content (see POM reference) ${project.version} 
${project.build.finalName} 
${project.artifactId} 
${project.build.directory}
project.basedir 
pom.basedir (deprecated
basedir (deprecated)
the directory containing the pom.xml file ${project.basedir}
project.baseUri 
pom.baseUri (deprecated)
the directory containing the pom.xml file as URI ${project.baseUri}
build.timestamp 
maven.build.timestamp
the UTC timestamp of build start, in yyyy-MM-dd'T'HH:mm:ss'Z' default format, which can be overridden with maven.build.timestamp.format POM property ${maven.build.timestamp}
* user properties, set from CLI with -Dproperty=value ${skipTests}
* model properties, such as project properties set in the pom ${any.key}
maven.home The path to the current Maven home. ${maven.home}
maven.version The version number of the current Maven execution (since 3.0.4). For example, "3.0.5". ${maven.version}
maven.build.version The full build version of the current Maven execution (since 3.0.4). For example, "Apache Maven 3.2.2 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19T14:51:28+01:00)". ${maven.build.version}
* Java system properties (see JDK reference) ${user.home} 
${java.home}
env.* 
*
environment variables ${env.PATH}
settings.* Local user settings (see settings reference) ${settings.localRepository}

Notice

  • after model interpolation, ${...} content can remain in the model that will be evaluated later when setting plugin parameters. This happens in particular with settings.* values for Settings Model,
  • encoding configuration have been defined as POM properties looking like POM content but not added to POM model to maintain compatibility with previous Maven versions: