网站首页设计模板,扮家家室内设计,网络推广公司加盟,自动建立wordpress您可以轻松地告诉Maven在JAR清单文件中包含工件的版本及其Git / SVN /…修订版#xff0c;然后在运行时通过getClass#xff08;#xff09;。getPackage访问该信息。 getImplementationVersion#xff08;#xff09; 。 #xff08;所有功劳归功于MarkusKrger和其他同事… 您可以轻松地告诉Maven在JAR清单文件中包含工件的版本及其Git / SVN /…修订版然后在运行时通过getClass。getPackage访问该信息。 getImplementationVersion 。 所有功劳归功于MarkusKrüger和其他同事。 在清单中包括Maven工件版本 注意如果您还想包含SCM修订版则实际上将不希望使用它请参见下文。 pom.xml project...buildpluginsplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-jar-plugin/artifactId...configurationarchivemanifestaddDefaultImplementationEntriestrue/addDefaultImplementationEntriesaddDefaultSpecificationEntriestrue/addDefaultSpecificationEntries/manifest/archive/configuration.../plugin/plugins/build...
/project 然后JAR文件的结果MANIFEST.MF将包括以下条目其值来自指示的属性 Built-By: ${user.name}
Build-Jdk: ${java.version}
Specification-Title: ${project.name}
Specification-Version: ${project.version}
Specification-Vendor: ${project.organization.name
Implementation-Title: ${project.name}
Implementation-Version: ${project.version}
Implementation-Vendor-Id: ${project.groupId}
Implementation-Vendor: ${project.organization.name} 规范供应商和实施供应商来自POM的组织/名称。 包括SCM修订版 为此您可以使用生成属性$ {buildNumber}的内部版本号Maven插件 也可以从Jenkins或Hudson对于Subversion为SVN_REVISION对于Git为GIT_COMMIT 传递的环境变量中检索它。 仅对于git您还可以使用maven-git-commit-id-plugin 该插件可以替换现有资源文件中的字符串例如$ {git.commit.id}使用maven的资源过滤必须启用。实际值或将它们全部输出到git.properties文件中。 让我们使用buildnumber-maven-plugin显式创建清单条目其中包含内部版本号即修订版 projectbuildpluginsplugin!-- Create the property $buildNumber holding the current Git revision --groupIdorg.codehaus.mojo/groupIdartifactIdbuildnumber-maven-plugin/artifactIdversion1.2/versionexecutionsexecutionphasevalidate/phasegoalsgoalcreate/goal/goals/execution/executionsconfigurationdoCheckfalse/doCheckdoUpdatefalse/doUpdate/configuration/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-jar-plugin/artifactIdversion2.4/versionconfigurationarchivemanifestEntriesImplementation-Title${project.name}/Implementation-Title!-- buildNumber is produced at runtime by buildnumber-maven-plugin --Implementation-Version${project.version} ${buildNumber}/Implementation-Version/manifestEntries/archive/configuration/plugin
...访问版本和修订版 如上所述您可以通过getClass。getPackage.getImplementationVersion和getClass。getPackage.getImplementationTitle访问代码中的清单条目。 资源资源 SO如何在运行时获取Maven Artifact版本 Maven存档器文档 参考 The Holy Java博客上的JCG合作伙伴 Jakub Holy可以在运行时访问工件的Maven和SCM版本 。 翻译自: https://www.javacodegeeks.com/2013/05/accessing-an-artifacts-maven-and-scm-versions-at-runtime.html