【问题标题】:How to get current maven goal version如何获取当前的 Maven 目标版本
【发布时间】:2016-04-28 17:37:55
【问题描述】:

如果你使用,在一个 maven 插件项目中

@Parameter(defaultValue = "${project}")
private MavenProject project;

然后你得到运行这个插件的项目。如何在 maven 目标本身中获取当前 Maven 目标的版本,更具体地说,是项目的 pom.xml 的这一部分?

<plugins>
      <plugin>
        <groupId>com.my.maven.plugins</groupId>
        <artifactId>my-maven-plugin</artifactId>
        <version>!! I want to get this !!</version>
      </plugin>
<plugins>

谢谢!

【问题讨论】:

    标签: java maven plugins runtime maven-plugin


    【解决方案1】:

    将此添加到您的魔力中:

    @Parameter( defaultValue = "${plugin}", readonly = true ) // Maven 3 only
    private PluginDescriptor plugin;
    

    其他可用实例可以在https://maven.apache.org/plugin-tools/maven-plugin-tools-annotations/index.html#Supported_Annotations找到

    【讨论】:

    • 谢谢会尽快尝试
    【解决方案2】:

    PluginDescriptor 仅适用于 Maven 3,如果你不想被 Maven 版本限制,你可以尝试添加这个

    @Parameter( defaultValue = "${mojoExecution}", readonly = true )
    private MojoExecution mojo;
    

    获取版本

    mojo.getPlugin().getVersion()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-27
      • 2019-06-11
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 2013-04-22
      • 2018-12-30
      • 2017-03-17
      相关资源
      最近更新 更多