Mojo的Build-Helper Maven插件可以在这里为您提供帮助。
有许多目标可用于帮助转换属性。
有
构建帮助器:正则表达式属性
build-helper:解析版本
build-helper:发布版本
正则表达式属性可能是您想要的,但是如果您的版本号符合“标准”,则另外两个可能会节省您的时间。
要使用正则表达式属性目标,您需要执行以下操作
<project> ... <build> <plugins> <plugin> <groupId>org.prehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>regex-property</id> <goals> <goal>regex-property</goal> </goals> <configuration> <name>tag.version</name> <value>${project.version}</value> <regex>^([0-9]+).([0-9]+).([0-9]+).([0-9]+).(-SNAPSHOT)?$</regex> <replacement>V$1_$2_$3_P$4</replacement> <failIfNoMatch>true</failIfNoMatch> </configuration> </execution> </executions> </plugin> </plugins> </build> ...</project>注意:我的regex可能会略有偏离,因此您应该测试上述内容。
注意:该属性值仅在此执行绑定到的阶段之后才可用于执行。绑定到的默认阶段是,
validate但是如果您处于不同的生命周期(例如站点生命周期),则该值将不可用。



