【Maven】查看插件配置参数

背景

工作中使用到很多的Maven插件,虽然可以从网上拷贝别人的配置来用,但是想要深入了解一个插件一共有哪些可用的配置参数,就无从下手了。

当然可以从插件的官方网站查看帮助手册,也可以通过Mavenhelp命令查看插件帮助,包括插件的简略和详细的描述信息,也可以查看插件所有的目标goal,以及插件的配置参数等。

帮助命令

在命令行下面,使用Mavenhelp:describe目标查看插件信息:mvn help:describe -Dplugin=插件标识

  • 通过plugin参数指定要查看的插件,插件标识可以是groupId:artifactId[:version]形式的,
  • 其中version是可选的,
  • 也可以是插件前缀,
  • 它是插件的简称,
  • 插件前缀和插件是一一对应的,
  • 这种对应关系存储在Maven仓库元数据中:https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
  • 比如插件前缀help和插件maven-help-plugin是对应的
<plugin>
  <name>Apache Maven Help Plugin</name>
  <prefix>help</prefix>
  <artifactId>maven-help-plugin</artifactId>
</plugin>

使用举例

下面查看maven-help-plugin插件的信息,即查看帮助命令自己的信息,下面两条命令是等价的:

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-help-plugin
mvn help:describe -Dplugin=help

输出查询结果如下

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.2.0:describe (default-cli) @ standalone-pom ---
[INFO] org.apache.maven.plugins:maven-help-plugin:3.2.0
 
Name: Apache Maven Help Plugin
Description: The Maven Help plugin provides goals aimed at helping to make
  sense out of the build environment. It includes the ability to view the
  effective POM and settings files, after inheritance and active profiles have
  been applied, as well as a describe a particular plugin goal to give usage
  information.
Group Id: org.apache.maven.plugins
Artifact Id: maven-help-plugin
Version: 3.2.0
Goal Prefix: help
 
This plugin has 8 goals:
 
help:active-profiles
  Description: Displays a list of the profiles which are currently active for
    this build.
 
help:all-profiles
  Description: Displays a list of available profiles under the current
    project.
    Note: it will list all profiles for a project. If a profile comes up with a
    status inactive then there might be a need to set profile activation
    switches/property.
 
help:describe
  Description: Displays a list of the attributes for a Maven Plugin and/or
    goals (aka Mojo - Maven plain Old Java Object).
 
help:effective-pom
  Description: Displays the effective POM as an XML for this build, with the
    active profiles factored in, or a specified artifact. If verbose, a comment
    is added to each XML element describing the origin of the line.
 
help:effective-settings
  Description: Displays the calculated settings as XML for this project,
    given any profile enhancement and the inheritance of the global settings
    into the user-level settings.
 
help:evaluate
  Description: Evaluates Maven expressions given by the user in an
    interactive mode.
 
help:help
  Description: Display help information on maven-help-plugin.
    Call mvn help:help -Ddetail=true -Dgoal=<goal-name> to display parameter
    details.
 
help:system
  Description: Displays a list of the platform details like system properties
    and environment variables.
 
For more information, run 'mvn help:describe [...] -Ddetail'
 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.613 s
[INFO] Finished at: 2021-10-12T15:38:22+08:00
[INFO] ------------------------------------------------------------------------

可以看到maven-help-plugin对应的插件前缀是help

Group Id: org.apache.maven.plugins
Artifact Id: maven-help-plugin
Version: 3.2.0
Goal Prefix: help

可以看到help:describe用来查看插件的属性和目标

help:describe
  Description: Displays a list of the attributes for a Maven Plugin and/or
    goals (aka Mojo - Maven plain Old Java Object).
  • 可以看到help命令自带的帮助: mvn help:help
  • 输出的结果基本和上面的相同
  • 这里更推荐使用help:describe命令

查看详细信息

通过在命令后追加-Ddetail参数,可以查看插件的详细信息:

简略信息:
mvn help:describe -Dplugin=help
详细信息:
mvn help:describe -Dplugin=help -Ddetail

详细信息输出如下,这是可以看到每个goal的配置参数说明

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.2.0:describe (default-cli) @ standalone-pom ---
[INFO] org.apache.maven.plugins:maven-help-plugin:3.2.0
 
Name: Apache Maven Help Plugin
Description: The Maven Help plugin provides goals aimed at helping to make
  sense out of the build environment. It includes the ability to view the
  effective POM and settings files, after inheritance and active profiles have
  been applied, as well as a describe a particular plugin goal to give usage
  information.
Group Id: org.apache.maven.plugins
Artifact Id: maven-help-plugin
Version: 3.2.0
Goal Prefix: help
 
This plugin has 8 goals:
 
help:active-profiles
  Description: Displays a list of the profiles which are currently active for
    this build.
  Implementation: org.apache.maven.plugins.help.ActiveProfilesMojo
  Language: java
 
  Available parameters:
 
    output
      User property: output
      Optional parameter to write the output of this help in a given file,
      instead of writing to the console.
      Note: Could be a relative path.
 
help:all-profiles
  Description: Displays a list of available profiles under the current
    project.
    Note: it will list all profiles for a project. If a profile comes up with a
    status inactive then there might be a need to set profile activation
    switches/property.
  Implementation: org.apache.maven.plugins.help.AllProfilesMojo
  Language: java
 
  Available parameters:
 
    output
      User property: output
      Optional parameter to write the output of this help in a given file,
      instead of writing to the console.
      Note: Could be a relative path.
 
help:describe
  Description: Displays a list of the attributes for a Maven Plugin and/or
    goals (aka Mojo - Maven plain Old Java Object).
  Implementation: org.apache.maven.plugins.help.DescribeMojo
  Language: java
 
  Available parameters:
 
    artifactId
      User property: artifactId
      The Maven Plugin artifactId to describe.
      Note: Should be used with groupId parameter.
 
    cmd
      User property: cmd
      A Maven command like a single goal or a single phase following the Maven
      command line:
      mvn [options] [<goal(s)>] [<phase(s)>]
 
    detail (Default: false)
      User property: detail
      This flag specifies that a detailed (verbose) list of goal (Mojo)
      information should be given.
 
    goal
      User property: goal
      The goal name of a Mojo to describe within the specified Maven Plugin. If
      this parameter is specified, only the corresponding goal (Mojo) will be
      described, rather than the whole Plugin.
 
    groupId
      User property: groupId
      The Maven Plugin groupId to describe.
      Note: Should be used with artifactId parameter.
 
    minimal (Default: false)
      User property: minimal
      This flag specifies that a minimal list of goal (Mojo) information should
      be given.
 
    output
      User property: output
      Optional parameter to write the output of this help in a given file,
      instead of writing to the console.
      Note: Could be a relative path.
 
    plugin
      Alias: prefix
      User property: plugin
      The Maven Plugin to describe. This must be specified in one of three
      ways:
 
      1.  plugin-prefix, i.e. 'help'
      2.  groupId:artifactId, i.e. 'org.apache.maven.plugins:maven-help-plugin'
      3.  groupId:artifactId:version, i.e.
        'org.apache.maven.plugins:maven-help-plugin:2.0'
 
    version
      User property: version
      The Maven Plugin version to describe.
      Note: Should be used with groupId/artifactId parameters.
 
help:effective-pom
  Description: Displays the effective POM as an XML for this build, with the
    active profiles factored in, or a specified artifact. If verbose, a comment
    is added to each XML element describing the origin of the line.
  Implementation: org.apache.maven.plugins.help.EffectivePomMojo
  Language: java
 
  Available parameters:
 
    artifact
      User property: artifact
      The artifact for which to display the effective POM.
      Note: Should respect the Maven format, i.e. groupId:artifactId[:version].
      The latest version of the artifact will be used when no version is
      specified.
 
    output
      User property: output
      Optional parameter to write the output of this help in a given file,
      instead of writing to the console.
      Note: Could be a relative path.
 
    verbose (Default: false)
      User property: verbose
      Output POM input location as comments.
 
help:effective-settings
  Description: Displays the calculated settings as XML for this project,
    given any profile enhancement and the inheritance of the global settings
    into the user-level settings.
  Implementation: org.apache.maven.plugins.help.EffectiveSettingsMojo
  Language: java
 
  Available parameters:
 
    output
      User property: output
      Optional parameter to write the output of this help in a given file,
      instead of writing to the console.
      Note: Could be a relative path.
 
    showPasswords (Default: false)
      User property: showPasswords
      For security reasons, all passwords are hidden by default. Set this to
      true to show all passwords.
 
help:evaluate
  Description: Evaluates Maven expressions given by the user in an
    interactive mode.
  Implementation: org.apache.maven.plugins.help.EvaluateMojo
  Language: java
 
  Available parameters:
 
    artifact
      User property: artifact
      An artifact for evaluating Maven expressions.
      Note: Should respect the Maven format, i.e. groupId:artifactId[:version].
      The latest version of the artifact will be used when no version is
      specified.
 
    expression
      User property: expression
      An expression to evaluate instead of prompting. Note that this must not
      include the surrounding ${...}.
 
    forceStdout (Default: false)
      User property: forceStdout
      This options gives the option to output information in cases where the
      output has been suppressed by using -q (quiet option) in Maven. This is
      useful if you like to use maven-help-plugin:evaluate in a script call
      (for example in bash) like this:
      RESULT=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
      echo $RESULT
      This will only printout the information which has been requested by
      expression to stdout.
 
    output
      User property: output
      Optional parameter to write the output of this help in a given file,
      instead of writing to the console. This parameter will be ignored if no
      expression is specified.
      Note: Could be a relative path.
 
help:help
  Description: Display help information on maven-help-plugin.
    Call mvn help:help -Ddetail=true -Dgoal=<goal-name> to display parameter
    details.
  Implementation: org.apache.maven.plugins.help.HelpMojo
  Language: java
 
  Available parameters:
 
    detail (Default: false)
      User property: detail
      If true, display all settable properties for each goal.
 
    goal
      User property: goal
      The name of the goal for which to show help. If unspecified, all goals
      will be displayed.
 
    indentSize (Default: 2)
      User property: indentSize
      The number of spaces per indentation level, should be positive.
 
    lineLength (Default: 80)
      User property: lineLength
      The maximum length of a display line, should be positive.
 
help:system
  Description: Displays a list of the platform details like system properties
    and environment variables.
  Implementation: org.apache.maven.plugins.help.SystemMojo
  Language: java
 
  Available parameters:
 
    output
      User property: output
      Optional parameter to write the output of this help in a given file,
      instead of writing to the console.
      Note: Could be a relative path.
 
 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.904 s
[INFO] Finished at: 2021-10-12T15:53:53+08:00
[INFO] ------------------------------------------------------------------------

查看指定目标

可以通过-Dgoal参数,查看指定目标的详细信息:

简略信息:
mvn help:describe -Dplugin=help -Dgoal=describe
详细信息:
mvn help:describe -Dplugin=help -Dgoal=describe -Ddetail

简略信息输出如下

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.2.0:describe (default-cli) @ standalone-pom ---
[INFO] Mojo: 'help:describe'
help:describe
  Description: Displays a list of the attributes for a Maven Plugin and/or
    goals (aka Mojo - Maven plain Old Java Object).
 
For more information, run 'mvn help:describe [...] -Ddetail'
 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.031 s
[INFO] Finished at: 2021-10-12T15:56:50+08:00
[INFO] ------------------------------------------------------------------------

详细信息输出如下

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.2.0:describe (default-cli) @ standalone-pom ---
[INFO] Mojo: 'help:describe'
help:describe
  Description: Displays a list of the attributes for a Maven Plugin and/or
    goals (aka Mojo - Maven plain Old Java Object).
  Implementation: org.apache.maven.plugins.help.DescribeMojo
  Language: java
 
  Available parameters:
 
    artifactId
      User property: artifactId
      The Maven Plugin artifactId to describe.
      Note: Should be used with groupId parameter.
 
    cmd
      User property: cmd
      A Maven command like a single goal or a single phase following the Maven
      command line:
      mvn [options] [<goal(s)>] [<phase(s)>]
 
    detail (Default: false)
      User property: detail
      This flag specifies that a detailed (verbose) list of goal (Mojo)
      information should be given.
 
    goal
      User property: goal
      The goal name of a Mojo to describe within the specified Maven Plugin. If
      this parameter is specified, only the corresponding goal (Mojo) will be
      described, rather than the whole Plugin.
 
    groupId
      User property: groupId
      The Maven Plugin groupId to describe.
      Note: Should be used with artifactId parameter.
 
    minimal (Default: false)
      User property: minimal
      This flag specifies that a minimal list of goal (Mojo) information should
      be given.
 
    output
      User property: output
      Optional parameter to write the output of this help in a given file,
      instead of writing to the console.
      Note: Could be a relative path.
 
    plugin
      Alias: prefix
      User property: plugin
      The Maven Plugin to describe. This must be specified in one of three
      ways:
 
      1.  plugin-prefix, i.e. 'help'
      2.  groupId:artifactId, i.e. 'org.apache.maven.plugins:maven-help-plugin'
      3.  groupId:artifactId:version, i.e.
        'org.apache.maven.plugins:maven-help-plugin:2.0'
 
    version
      User property: version
      The Maven Plugin version to describe.
      Note: Should be used with groupId/artifactId parameters.
 
 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.162 s
[INFO] Finished at: 2021-10-12T15:57:13+08:00
[INFO] ------------------------------------------------------------------------

其他命令

该帮助插件还有很多有用的goal,下面仅列出几个常用的,更多的请自行尝试。

  • 查看当前pom.xml具体生效的结果,并且输出到文件: mvn help:effective-pom -Doutput=EffectivePom.xml
  • 查看pom中生效的profile: mvn help:active-profiles -N
  • 查看系统所有环境变量: mvn help:system
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 在Maven中进行部署时,你需要在项目的pom.xml文件中配置部署相关的插件参数。 以下是一个使用Maven进行部署的示例配置: 1. 配置Maven插件 在pom.xml文件的<build>标签中,添加以下插件配置: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>3.0.0-M1</version> <configuration> <updateReleaseInfo>true</updateReleaseInfo> </configuration> </plugin> </plugins> </build> ``` 这将使用maven-deploy-plugin插件将构建好的jar包或war包部署到Maven仓库中。 2. 配置Maven仓库 在pom.xml文件的<distributionManagement>标签中,添加以下仓库配置: ```xml <distributionManagement> <repository> <id>my-repository</id> <name>My Repository</name> <url>http://myserver/repo/</url> </repository> </distributionManagement> ``` 这将把项目部署到一个名为“my-repository”的Maven仓库中。 3. 配置凭证 如果需要验证身份以便访问Maven仓库,你需要在settings.xml文件中添加Maven凭证。 在settings.xml文件中,添加以下服务器配置: ```xml <servers> <server> <id>my-repository</id> <username>my-username</username> <password>my-password</password> </server> </servers> ``` 这将允许Maven插件使用用户名和密码进行身份验证。 以上是Maven部署的基本配置。根据具体的项目需求和部署方式,可能需要进行其他配置。 ### 回答2: 要查看Maven下的部署配置,可以按照以下步骤进行: 1. 打开项目的pom.xml文件。该文件通常位于项目的根目录下。在pom.xml中可以找到项目的依赖和插件配置。 2. 首先,检查pom.xml中的`<build>`标签。在这里,我们可以配置Maven的构建相关信息,包括部署的目标位置。 3. 在`<build>`标签内,我们可以查看`<plugins>`标签。这里面列出了项目所使用的所有插件配置。寻找与部署相关的插件配置。 4. 需要特别注意的是`maven-deploy-plugin`和`maven-war-plugin`插件。这些插件用于将构建好的项目部署到指定的目标位置。 5. 如果找到了`maven-deploy-plugin`或`maven-war-plugin`插件,可以进一步查看配置参数。例如,对于`maven-deploy-plugin`,可以查看`<configuration>`标签内的参数配置,例如`<distributionManagement>`和`<repository>`。 6. 除了pom.xml文件,还可以查看项目的Maven配置文件`settings.xml`。该文件通常位于用户主目录下的`.m2`文件夹内。在`settings.xml`中,可以找到与部署相关的服务器和凭证配置。 通过以上步骤,我们可以查看Maven下的部署配置,了解项目的部署目标位置和相关插件配置。 ### 回答3: 要查看Maven下的部署配置,需要执行以下步骤: 1. 打开项目的pom.xml文件,这是Maven项目的主要配置文件。在该文件中,可以检查和修改项目的插件和依赖项配置。 2. 查找并检查 `<build>` 元素,这是用来配置项目构建过程的部分。在该部分中,可以确定是否有关于部署的插件配置。如果没有,请查看 `<plugins>` 元素中是否包含与部署相关的插件配置。 3. 如果找到了与部署相关的插件配置,检查插件的详细配置。这些配置通常包括服务器的URL、用户名、密码等信息。确保这些信息与实际部署环境匹配,并根据需要进行修改。 4. 如果找不到与部署相关的插件配置,可以在 `<plugins>` 元素中添加适当的插件来实现部署。通常使用的插件包括 `maven-deploy-plugin` 和 `maven-release-plugin`。在添加插件后,配置插件的详细信息,包括服务器的URL、用户名、密码等。 5. 在配置插件后,可以使用Maven命令来执行部署。常用的命令包括 `mvn deploy` 和 `mvn release:prepare`。这些命令会根据配置将项目部署到指定的服务器上。 总结起来,要查看Maven下的部署配置,需要检查pom.xml文件中的插件配置,确认插件的详细信息与实际部署环境匹配,并使用相应的Maven命令执行部署。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

太空眼睛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值