2 回答
TA贡献1906条经验 获得超3个赞
使用 build-helper-maven-plugin (通过build helper 插件不解析项目版本)
maven-antrun-plugin 仅用于显示结果
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<propertyPrefix>parsedVersion</propertyPrefix>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Major: ${parsedVersion.majorVersion}</echo>
<echo>Minor: ${parsedVersion.minorVersion}</echo>
<echo>Incremental: ${parsedVersion.incrementalVersion}</echo>
<echo>Qualifier: ${parsedVersion.qualifier}</echo>
<echo>BuildNumber: ${parsedVersion.buildNumber}</echo>
<echo>Project version: ${project.version}</echo>
<echo>No qualifier: ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
输出:
[INFO] --- maven-antrun-plugin:1.1:run (default) @ XXX ---
[INFO] Executing tasks
[echo] Major: 1
[echo] Minor: 2
[echo] Incremental: 0
[echo] Qualifier: SNAPSHOT
[echo] BuildNumber: 0
[echo] Project version: 1.2.0-SNAPSHOT
[echo] No qualifier: 1.2.0
添加回答
举报