行家 ${project.version.prefix}

我们有一个多模块 java 项目,其中每个模块都有 pom.xml。我看到我们在 pom.xml 中有 ${project.version} ,它基本上获取了项目版本。有没有像 ${project.version.prefix} 这样的东西也会得到项目版本减去 SNAPSHOT?



蝴蝶不菲
浏览 168回答 2
2回答

一只名叫tom的猫

使用 build-helper-maven-plugin (通过build helper 插件不解析项目版本)maven-antrun-plugin 仅用于显示结果&nbsp;<plugin>&nbsp; &nbsp; <groupId>org.codehaus.mojo</groupId>&nbsp; &nbsp; <artifactId>build-helper-maven-plugin</artifactId>&nbsp; &nbsp; <version>1.7</version>&nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; <phase>validate</phase>&nbsp; &nbsp; &nbsp; &nbsp; <id>parse-version</id>&nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>parse-version</goal>&nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <propertyPrefix>parsedVersion</propertyPrefix>&nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; </executions>&nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; <artifactId>maven-antrun-plugin</artifactId>&nbsp; &nbsp; <version>1.1</version>&nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; <phase>validate</phase>&nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>run</goal>&nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tasks>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>Major: ${parsedVersion.majorVersion}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>Minor: ${parsedVersion.minorVersion}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>Incremental: ${parsedVersion.incrementalVersion}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>Qualifier: ${parsedVersion.qualifier}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>BuildNumber: ${parsedVersion.buildNumber}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>Project version: ${project.version}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <echo>No qualifier: ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</echo>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tasks>&nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; </executions>&nbsp; </plugin>输出:&nbsp;[INFO] --- maven-antrun-plugin:1.1:run (default) @ XXX ---&nbsp;[INFO] Executing tasks&nbsp;[echo] Major: 1&nbsp;[echo] Minor: 2&nbsp;[echo] Incremental: 0&nbsp;[echo] Qualifier: SNAPSHOT&nbsp;[echo] BuildNumber: 0&nbsp;[echo] Project version: 1.2.0-SNAPSHOT&nbsp;[echo] No qualifier: 1.2.0

HUWWW

Maven 中没有任何固有的东西可以用于此,但您可以配置build-helper-maven-plugin以设置一个可以解析数据的属性。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java