假设我们需要向一些工件(jar,war等)添加内部版本号。 在这里,我想演示buildnumber-maven-plugin的用法。

这篇文章基于:

  • http://mojo.codehaus.org/buildnumber-maven-plugin/usage.html
  • http://www.site.lalitbhatt.com/maven-build-number-plugin
  • http://blog.peterlynch.ca/2009/11/buildnumber-maven-plugin-helpful.html
  • http://apollo.ucalgary.ca/tlcprojectswiki/index.php/Public/Project_Versioning_-_Best_Practices#Build_Versioning

我们有一些项目,需要在jar清单文件中包含不基于VCS(SVN,Git,Mercurial等)修订版本的顺序内部版本号。 让我们创建适当的pom.xml文件,并实施一个小型演示以验证结果。

生成Maven项目

$ mvn archetype:generate -DgroupId=org.halyph -DartifactId=buildNoTest\
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false

创建pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelversion>4.0.0</modelversion><groupid>org.halyph</groupid><artifactid>buildNoTest</artifactid><packaging>jar</packaging><version>1.0-SNAPSHOT</version><name>buildNoTest</name><url>http://maven.apache.org</url><dependencies><dependency><groupid>junit</groupid><artifactid>junit</artifactid><version>3.8.1</version><scope>test</scope></dependency></dependencies><properties><project.build.sourceencoding>UTF-8</project.build.sourceencoding></properties><!-- If you have access to scm then you can place actual url's. Otherwise with <revisionOnScmFailure /> you can give some fake URLs as follows. --><scm><connection>scm:svn:http://none</connection><developerconnection>scm:svn:https://none</developerconnection><url>scm:svn:https://none</url></scm><build><resources><resource><directory>src/main/resources</directory></resource><resource><directory>src/main/filtered-resources</directory><filtering>true</filtering></resource></resources><plugins><plugin><groupid>org.codehaus.mojo</groupid><artifactid>buildnumber-maven-plugin</artifactid><version>1.1</version><executions><execution><phase>generate-resources</phase><goals><goal>create</goal></goals></execution></executions><configuration><!-- doCheck and doUpdate actually talk to repository if it's true,Check would check that there are no local changes. Update would update it --><docheck>false</docheck><doupdate>false</doupdate><!-- This ensures that even if we are not connected to scm than alsotake the version from local .svn file --><revisiononscmfailure><!--Generate sequence build number based on:build number and timestamp      --><format>Build: #{0} ({1,date})</format><items><item>buildNumber\d*</item><item>timestamp</item></items></revisiononscmfailure></configuration></plugin><plugin><groupid>org.apache.maven.plugins</groupid><artifactid>maven-jar-plugin</artifactid><version>2.1</version><configuration><archive><!-- will put the entries into META-INF/MANIFEST.MF file --><manifestentries><implementation-version>${project.version}</implementation-version><implementation-build>${buildNumber}</implementation-build></manifestentries></archive></configuration></plugin></plugins></build>
</project>

创建演示应用程序以验证结果

package org.halyph;import java.io.IOException;
import java.util.ResourceBundle;
import java.util.jar.Attributes;
import java.util.jar.Manifest;public class App
{public static void main( String[] args ) throws IOException{System.out.println('Verify Resource bundle' );// Check filtered resources based on generated build numberResourceBundle bundle = ResourceBundle.getBundle( 'build' );String msg = bundle.getString( 'build.message' );System.out.println(msg);System.out.println('\nVerify Generated MANIFEST.MF Properties' );// Check Manifest file based on generated build numberManifest mf = new Manifest();mf.read(Thread.currentThread().getContextClassLoader().getResourceAsStream('META-INF/MANIFEST.MF'));Attributes atts = mf.getMainAttributes();System.out.println('Implementation-Versio: ' + atts.getValue('Implementation-Version'));System.out.println('Implementation-Build: ' + atts.getValue('Implementation-Build'));}
}

多次构建应用程序并运行

$ mvn install
$ java -cp target\buildNoTest-1.0-SNAPSHOT.jar org.halyph.App
Verify Resource bundle
Build: #3 (Jun 27, 2012)Verify Generated MANIFEST.MF Properties
Implementation-Versio: 1.0-SNAPSHOT
Implementation-Build: Build: #3 (Jun 27, 2012)

摘要

  1. 我们应该通过将伪造的<scm>部分添加到pom.xml中并将<revisionOnScmFailure />添加到buildnumber-maven-plugin <configuration>中,通知buildnumber-maven-plugin我们将不使用版本控制修订作为内部版本号。
  2. 已实现的自定义内部版本号格式,请参阅buildnumber-maven-plugin <配置> / <格式>和<配置> / <项目>。
  3. 在jar清单中添加了内部版本号,请参阅maven-jar-plugin pom.xml部分
  4. 测试生成的内部版本号是否可以正确添加到过滤的资源中
  • 创建的src \ main \ filtered-resources \ build.properties文件
build.message=${buildNumber}
  • 添加了资源过滤,请参见<resource>标志<filtering> true </ filtering>部分
  • 演示应用程序验证jar清单文件中的过滤资源和内部版本号
  • 您可以git clone这个项目https://github.com/halyph/blog-sandbox/tree/master/Maven/blogpost_062712

    参考: Maven内部版本号插件–我们的JCG合作伙伴 Orest Ivasiv的示例用法,来自Knowledge Is Everything博客。

翻译自: https://www.javacodegeeks.com/2012/10/maven-build-number-plugin-sample-usage.html

Maven内部版本号插件–用法示例相关推荐

  1. maven 版本号插件_Maven内部版本号插件–用法示例

    maven 版本号插件 假设我们需要向一些工件(jar,war等)添加内部版本号. 在这里,我想演示buildnumber-maven-plugin的用法. 这篇文章基于: http://mojo.c ...

  2. 鼠标移动响应php程序,jQuery实现的响应鼠标移动方向插件用法示例【附源码下载】...

    本文实例讲述了jQuery实现的响应鼠标移动方向插件用法.分享给大家供大家参考,具体如下: HTML代码如下: www.jb51.net jQuery响应鼠标移动 *{margin:0;padding ...

  3. php this指针的用法,C#_C#中this指针的用法示例,本文实例展示了C#中this指针的 - phpStudy...

    C#中this指针的用法示例 本文实例展示了C#中this指针的用法,对于初学者进一步牢固掌握C#有很大帮助,具体内容如下: 一.this指针是什么: 这里有一些面向对象编程的概念需要说明:类(Cla ...

  4. Java:Lombok插件用法笔记

    1.Lombok是什么东东? 官方介绍Lombok项目是一个Java库,它可以自动嵌入你的编辑器和构建工具中,从而减少你的代码量.永远不要再写另一个getter或equals方法,它带有一个注释的你的 ...

  5. maven 版本号插件_测试Maven版本插件自动递增版本号

    maven 版本号插件 抽象 Maven版本插件是一个非常强大的工具,我在很大程度上依赖于它来协调软件版本. 通常,软件发行版本号遵循简单的1.0.0.0-SNAPSHOT格式. 但是最近我需要在版本 ...

  6. 构建maven项目插件_如何构建一个Maven插件

    构建maven项目插件 使用Okta的身份管理平台轻松部署您的应用程序 使用Okta的API在几分钟之内即可对任何应用程序中的用户进行身份验证,管理和保护. 今天尝试Okta. 由于其插件生态系统的普 ...

  7. 测试Maven版本插件自动递增版本号

    抽象 Maven版本插件是一个非常强大的工具,我在很大程度上依赖于它来协调软件版本. 通常,软件发行版本号遵循简单的1.0.0.0-SNAPSHOT格式. 但是最近我需要在版本号中添加限定符-类似于1 ...

  8. maven配置testng_TestNG Maven Surefire插件配置

    maven配置testng TestNG Maven surefire plugin configurations let us define which tests to execute when ...

  9. js截取图片 裁剪图片之cropper.js插件用法详解

    js截取图片 裁剪图片之cropper.js插件用法详解 源码:https://github.com/fengyuanchen/cropper 引入+使用 <link href="/p ...

最新文章

  1. ACR2010_依那西普改善RA患者骨代谢
  2. Vue.js实现前段评论展示
  3. 微信小程序图表插件 echarts-for-weixin
  4. 应该允许公司报复黑客吗?
  5. linux同步数据库,Linux两台服务器mysql数据库同步
  6. linux 编辑文件vim,linux下通过vim编辑文件的方法
  7. java opencv 轮廓检测,OpenCV 轮廓检测 - 雷霄骅(leixiaohua1020)的个人页面 - OSCHINA - 中文开源技术交流社区...
  8. Pandas 表连接(Merge,join,concatenate)
  9. 1002: Prime Path
  10. android sdk环境配置_Mac 配置adb环境的方法
  11. 如何让文章的内容更吸引人
  12. 总体分布概况符合无界约翰逊分布(johnsonsu)的情况
  13. DirectAdmin+阿里云免费SSL证书 面板里安装SSL
  14. 解决 Chrome 浏览器跨域加载本地文件的问题
  15. 机房动环监控系统有哪些告警功能,机房动环监控系统是什么?
  16. 电商商家玩抖音裂变营销,必须要知道的数据分析知识-下秒数据
  17. 尚硅谷设计模式学习(1)---[设计模式七大原则]
  18. python将英文翻译为中文_Python使用百度翻译开发平台实现英文翻译为中文功能示例...
  19. LightOJ 1079 Just another Robbery
  20. Android lua编辑工具,mlua app下载

热门文章

  1. 转:运维监控系统-监控项及指标的梳理
  2. system health_可重复使用的MicroProfile Health探针
  3. java 迁移数据_Java 9迁移指南:七个最常见的挑战
  4. 技术停滞_检测和测试停滞的流– RxJava常见问题解答
  5. taskexecutor_弹簧和线程:TaskExecutor
  6. java 存储数据到文件中_本机速度文件支持的“纯” Java大数据存储
  7. spring3.0异步_在Spring 4.2中更简单地处理异步事务绑定事件
  8. spark wai_WAI-ARIA对自动完成小部件的支持
  9. ejb生命周期_EJB 3.x:生命周期和并发模型(第1部分)
  10. Java是发展的垫脚石。 学习吧!