如何获得Maven版本的semver Major部分? [英] How to get the semver Major part of a Maven version?

查看:88
本文介绍了如何获得Maven版本的semver Major部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取project.version的主版本(<Major>.<Minor>.<Patch>)?

Is it possible to get the major version (<Major>.<Minor>.<Patch>) of the project.version?

例如,如果我的版本是1.3.4,我想让1以后在相同pom.xml的配置中使用它

For example if my version is 1.3.4, I'd like to get 1 to later use it in a configuration of the same pom.xml

类似的东西:

<configuration>
  <name>project_name.${project.version:major}</name>
</configuration>

如果没有,还有哪些选择?

If not, what are the alternatives?

推荐答案

找到了它. build-helper-maven-plugin 可以解析-删除该版本的组件.

Found it. The build-helper-maven-plugin has the ability to parse-out the components of the version.

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

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <echo>[version] ${project.version}</echo>
                <echo>[majorVersion] ${parsedVersion.majorVersion}</echo>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

这篇关于如何获得Maven版本的semver Major部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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