Java 在pom.xml中自动增加版本号并在应用程序中显示
我看到这个问题被问了很多次,但都没有令人满意的答案:让我们假设您有maven项目生产一些jar(java桌面应用程序)。 如何在pom.xml中定义版本号,该版本号将在适当时自动递增(甚至手动递增,无所谓)(例如,在每个构建中),但有可能将此版本加载到应用程序中?Java 在pom.xml中自动增加版本号并在应用程序中显示,java,maven,build,jar,version,Java,Maven,Build,Jar,Version,我看到这个问题被问了很多次,但都没有令人满意的答案:让我们假设您有maven项目生产一些jar(java桌面应用程序)。 如何在pom.xml中定义版本号,该版本号将在适当时自动递增(甚至手动递增,无所谓)(例如,在每个构建中),但有可能将此版本加载到应用程序中? 目标是为用户显示他当前使用的应用程序版本。您可以选择以下四个选项: 使用Maven默认创建的pom.properties文件 使用MANIFST.MF文件提供的信息。有几种方法可以获得这些信息 创建一个属性,该属性在生成过程中被过滤,
目标是为用户显示他当前使用的应用程序版本。您可以选择以下四个选项:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<revisionOnScmFailure>UNKNOWN</revisionOnScmFailure>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
</configuration>
<executions>
<execution>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
org.codehaus.mojo
buildnumber maven插件
1.2
不为人知
真的
javasvn
创造
如果你有一个新版本,我不会改变这个版本。将Jenkins的buildnumber或您正在使用的任何CI解决方案添加到MANIFEST.MF文件中可能会很有用,但是我会使用Maven版本,在发布的情况下,它将从
1.0-SNAPSHOT
更改为1.0
谢谢你的回答-最后我得到了过滤属性文件和自动增量版本的Maven插件(buildnumber Maven插件也可以使用)。MF根本不适合我-我使用OpenJDK,出于某种原因,它拒绝加载ImplementationVersion和类似的标记(它们总是空的)。我没有时间进一步调试。
public class TheVersionClass {
public TheVersionClass() {
System.out.println( " Implementation Title:" + this.getClass().getPackage().getImplementationTitle() );
System.out.println( " Implementation Vendor:" + this.getClass().getPackage().getImplementationVendor() );
System.out.println( "Implementation Version:" + this.getClass().getPackage().getImplementationVersion() );
System.out.println( " Specification Tile:" + this.getClass().getPackage().getSpecificationTitle() );
System.out.println( " Specification Vendor:" + this.getClass().getPackage().getSpecificationVendor() );
System.out.println( " Specification Version:" + this.getClass().getPackage().getSpecificationVersion() );
}
}
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<revisionOnScmFailure>UNKNOWN</revisionOnScmFailure>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
</configuration>
<executions>
<execution>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>