Apache Maven help插件介绍和pom.xml中进行property属性的定义、引用

本文介绍了Maven的Help插件及其使用,特别是`help:evaluate`目标的详细操作。通过这个目标,可以查看POM文件中的属性值,系统属性,环境变量,项目信息以及settings.xml中的设置。这对于理解和调试Maven构建过程非常有帮助。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. help插件和目标

详细的使用请参考官网:https://maven.apache.org/plugins/maven-help-plugin

目标说明
help:active-profiles列出当前工程已激活的profile
help:all-profiles列出当前工程所有可用profile
help:describe描述一个插件和Mojo(Maven Old Java Object,插件的一个执行目标)的属性
help:effective-pom以XML格式展示有效POM
help:effective-settings为当前工程以XML格式展示计算得到的settings配置
help:evaluate在交互模式下对Maven表达式进行计算
help:system显示平台详细信息列表,如系统属性和环境变量

2. 使用help:evaluate查看属性值

2.1 查看pom.xml定义的property

在pom.xml中定义的property如下

  <properties>
    <my-key>my-value</my-key>
  </properties>

然后交互式的查看属性值

C:\Users\dell\Desktop\maven-learn>mvn help:evaluate
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.hh:maven-learn >-------------------------
[INFO] Building my-project 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.2.0:evaluate (default-cli) @ maven-learn ---
[INFO] No artifact parameter specified, using 'com.hh:maven-learn:jar:0.1' as project.
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${my-key}
[INFO]
my-value
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:

2.2 查看系统的属性值

可以获取系统的属性值,也就是Java中的System.getProperties()可以获取到的属性

[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${java.runtime.version}
[INFO]
11.0.15+10-LTS
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:

2.3 查看系统的环境变量

[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${env.JAVA_HOME}
[INFO]
d:install_software\java11\zulu11.56.19-ca-jdk11.0.15-win_x64
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:

2.4 查看project的pom.xml中的属性值

使用表达式${project.xxx}可以访问当前pom.xml中的元素值

[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${project.organization.name}
[INFO]
my-company
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${project.licenses[0]}
[INFO]
<license>
  <name>Apache License, Version 2.0</name>
  <url>https://www.apache.org/licenses/LICENSE-2.0</url>
  <location>
    <lineNumber>55</lineNumber>
    <columnNumber>14</columnNumber>
    <source>
      <modelId>com.hh:maven-learn:0.1</modelId>
      <location>C:\Users\dell\Desktop\maven-learn\pom.xml</location>
    </source>
  </location>
  <nameLocation>
    <lineNumber>56</lineNumber>
    <columnNumber>13</columnNumber>
    <source reference="../../location/source"/>
  </nameLocation>
  <urlLocation>
    <lineNumber>57</lineNumber>
    <columnNumber>12</columnNumber>
    <source reference="../../location/source"/>
  </urlLocation>
</license>
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:

2.5 访问maven的settings.xml中的属性值

[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
${settings.localRepository}
[INFO]
D:\install_software\maven\apache-maven-3.8.6\repository
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值