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?:
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐