我注意到,在Maven工件的罐子中,项目.版本属性包含在两个文件中:
META-INF/maven/${groupId}/${artifactId}/pom.properties
META-INF/maven/${groupId}/${artifactId}/pom.xml
有没有推荐的在运行时阅读此版本的方法?
我注意到,在Maven工件的罐子中,项目.版本属性包含在两个文件中:
META-INF/maven/${groupId}/${artifactId}/pom.properties
META-INF/maven/${groupId}/${artifactId}/pom.xml
有没有推荐的在运行时阅读此版本的方法?
您不需要访问特定于Maven的文件来获取任何给定库/类的版本信息.
您只需使用getClass().getPackage().getImplementationVersion()
即可获得存储在数据库中的版本信息.jar文件MANIFEST.MF
幸运的是Maven足够聪明不幸的是,Maven在默认情况下也没有将正确的信息写入 list !
相反,必须将maven-jar-plugin
的<archive>
配置元素修改为addDefaultImplementationEntries
,将addDefaultSpecificationEntries
设置为true
,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
理想情况下,这种配置应该放入公司pom
或另一个基础-POM中.
<archive>
元素的详细文档可以在Maven Archive documentation中找到.