无法访问POM属性中的parsedVersion值 [英] Cannot access parsedVersion value in pom properties

查看:20
本文介绍了无法访问POM属性中的parsedVersion值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven插件:

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>parse-version</id>
                    <goals>
                        <goal>parse-version</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

解析项目版本。工作正常:

[INFO] --- build-helper-maven-plugin:3.0.0:parse-version (parse-version)
[INFO]
[INFO] --- maven-antrun-plugin:1.1:run (default)
[INFO] Executing tasks

 [echo] Major: 2
 [echo] Minor: 0
 [echo] Incremental: 0
 [echo] Qualifier: SNAPSHOT
 [echo] BuildNumber: 0

但是,如果我要在配置文件属性中使用属性parsedVersion.MajorVersion,则无法解析该属性。

    <profiles>
    <profile>
        <id>local</id>
        <properties>
            <majorVersion>${myMajorVersion}</majorVersion>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
</profiles>

<properties>
    <myMajorVersion>${parsedVersion.majorVersion}</myMajorVersion>

有什么想法吗?

推荐答案

这里的问题是,属性值替换是在读入POM时完成的,而构建帮助器是在验证阶段运行的。当您在元素中读取这些属性时,尚未设置它们。

您可能要做的就是使用Build-helper:regex-Property Mojo设置一个基于正则表达式的属性(请参见https://www.mojohaus.org/build-helper-maven-plugin/regex-property-mojo.html)。在您的配置文件中,可以将属性设置为固定值,在正则表达式中,如果该值匹配,则将其替换为 您想要的解析值。只要您正在设置的属性值在验证阶段之后使用,则它将被设置为使用它的正确的值。

这篇关于无法访问POM属性中的parsedVersion值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆