行家 ${project.version.prefix}

maven ${project.version.prefix}

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

Maven 中没有任何可用于此目的的固有内容,但您可以配置 build-helper-maven-plugin 以设置一个 属性,您可以在其中解析数据。

使用 build-helper-maven-plugin(通过 build helper plugin not parsing project version

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