Maven内部版本号插件–用法示例

假设我们需要向一些工件(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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/371590.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python魔法方法(magic method)细解几个常用魔法方法(下)

接上文&#xff0c;再介绍最后几个常用的魔法方法。 关于__dict__: 先上个例子&#xff1a; class Test(object):fly Truedef __init__(self, age):self.age age __dict__魔法方法可以被称为系统&#xff0c;他是存储各分层属性的魔法方法。__dict__中&#xff0c;键为属性名…

AIX下RAC搭建 Oracle10G(六)dbca建库

AIX下RAC搭建系列 AIX下RAC搭建 Oracle10G&#xff08;六&#xff09;dbca建库 环境 节点 节点1 节点2 小机型号 IBM P-series 630 IBM P-series 630 主机名 AIX203 AIX204 交换机 SAN光纤交换机 存储 SAN T3存储 大纲流程例如以下&#xff1a; 第一部分&#xff1…

php string slice,substring()与str.slice()区别

当接收的参数是负数时&#xff0c;slice会将它字符串的长度与对应的负数相加&#xff0c;结果作为参数&#xff1b;substr则仅仅是将第一个参数与字符串长度相加后的结果作为第一个参数&#xff1b;substring则干脆将负参数都直接转换为0。测试代码如下&#xff1a;var test h…

JavaOne 2012:掌握Java部署

在吃完一次JavaClass 2012午餐会的意大利经典组合后&#xff0c;我前往希尔顿帝国宴会厅B观看了演示“掌握Java部署”。 来自Oracle的发言人是Mark Howe和Igor Nekrestyano Howe表示&#xff0c;部署团队的目标是帮助Java开发人员将其应用程序部署到所选平台。 他首先讨论了“功…

数组删除奇数编号的数据求最后的元素

//abcd...s 这19个字符循环106次成一个长度2014的字符串&#xff0c;然后删除第奇数个&#xff0c;得到小串&#xff0c;再删&#xff0c;最后的字符是&#xff1f; #define _CRT_SECURE_NO_DEPRECATE #include<stdio.h> #include<windows.h> #include<string.…

php 提高吞吐量,如何提高网站的吞吐量

吞吐量定义百科吞吐量是指对网络、设备、端口、虚电路或其他设施&#xff0c;单位时间内成功地传送数据的数量(以比特、字节、分组等测量)。以上的定义比较宽泛&#xff0c;定义到网站或者接口的吞吐量是这样的&#xff1a;吞吐量是指系统在单位时间内处理请求的数量。这里有一…

ubuntu下如何查找某个文件的路径

1.whereis 文件名 特点:快速,但是是模糊查找,例如 找 #whereis mysql 它会把mysql,mysql.ini,mysql.*所在的目录都找出来. 2.find / -name 文件名 特点:准确,但速度慢,消耗资源大,例如我想找到PHP.ini的准确位置,就需要用 #find / -name php.ini 3.locate 文件名 强力推荐的方…

事件的学习

1.鼠标单击事件( onclick &#xff09;: onclick是鼠标单击事件&#xff0c;当在网页上单击鼠标时&#xff0c;就会发生该事件。同时onclick事件调用的程序块就会被执行&#xff0c;通常与按钮一起使用。 <!DOCTYPE HTML> <html> <head> <meta http-equiv…

使用您自己的规则在Eclipse中自定义PMD

PMD是非常好的Java代码扫描程序&#xff0c;可帮助您避免潜在的编程问题。 它可以轻松扩展以满足您的需求&#xff0c;并且本文将为您带来与JPA的Enumerated注释用法相关的自定义PMD规则的简单示例。 在继续阅读之前&#xff0c;您应该检查我以前的文章之一-JPA-Enumerated def…

切换oracle用户impdp,Oracle 12c pdb使用expdp/impdp导入导出

12c推出了可插拔数据库&#xff0c;在一个容器cdb中以多租户的形式同时存在多个数据库pdb。在为pdb做数据泵导入导出时和传统的数据库有少许不同。1&#xff0c;需要为pdb添加tansnames2&#xff0c;导入导出时需要在userid参数内指定其tansnames的值&#xff0c;比如 useridus…

搭建mysql集群,使用Percona XtraDB Cluster搭建

Percona XtraDB Cluster提供的特性有&#xff1a;1.同步复制&#xff0c;事务要么在所有节点提交或不提交。2.多主复制&#xff0c;可以在任意节点进行写操作。3.在从服务器上并行应用事件&#xff0c;真正意义上的并行复制。4.节点自动配置。5.数据一致性&#xff0c;不再是异…

使用NoSQL实现实体服务–第4部分:Java EE

现在&#xff0c;我已经准备好了框架式的合同优先型Web服务&#xff0c;并使用Ektorp和CouchDB创建了数据访问层 &#xff0c;是时候将它们连接到一个可以正常工作的实体服务中了 。 为此&#xff0c;我将使用Java EE和Glassfish 3.1。 值得注意的是&#xff0c;对于他的那种R&…

yii2之DetailView小部件

DetailView小部件用于展示单条数据记录&#xff0c;可配置属性很少&#xff0c;使用也很简单&#xff0c;直接贴代码&#xff0c;一看就懂&#xff01; yii小部件数据小部件DetailView的使用示例&#xff1a; <? DetailView::widget([model > $user,//模型对象&#xff…

克隆安装oracle,Oracle 之 Cloning $oracle_home (克隆安装oracle软件)

用途&#xff1a;Cloning an Oracle Home &#xff0c; 可以免去多台机器重复安装oracle软件1、停止相关进程[rootnode1 bin]# ./crsctl stop cluster -all2、打包 dbhome_1 目录[rootnode1 11.2.0]# cd /u01/app/oracle/product/11.2.0/[rootnode1 11.2.0]# tar -zcvpf db_1.b…

gitlab的安装和基本维护

基本介绍 GitLab是一个自托管的Git项目仓库&#xff0c;可以自己搭建个人代码管理的仓库&#xff0c;功能与github类似。 安装 操作系统&#xff1a;CentOS6.5 gitlab官网下载安装地址&#xff1a;https://about.gitlab.com/downloads/#centos6 1.安装依赖的包 yum install cur…

Spring配置文件和Java配置

我的上一个博客介绍了Spring 3.1的配置文件&#xff0c;并解释了使用它们的业务案例&#xff0c;并演示了它们在Spring XML配置文件中的用法。 但是&#xff0c;似乎很多开发人员更喜欢使用Spring的基于Java的应用程序配置&#xff0c;因此Spring设计了一种使用带有现有Configu…

php 删除单个文件大小,php删除指定大小的jpg文件

function actionZmdel(){//set_time_limit(0);$dir dirname(dirname(dirname(dirname(__FILE__))))./2012jxgwyimg;$dirarr scandir($dir);echo 正在删除...;foreach($dirarr as $subdir){if($subdir ! . && $subdir ! ..){$path $dir./.$subdir;$files glob($path…

2017寒假零基础学习Python系列之函数之 函数之定义可变参数

若想让函数接受任意个参数&#xff0c;就可以定义一个可变的参数&#xff1a; def fn(*args): print args fn() >>>() fn(1,2,5,6) >>>(1,2,5,6) 原理是Python解释器把传入的一组参数封装在一个tuple传递给可变参数&#xff0c;因此在函数内部&#xff0c;直…

在Windows上构建OpenJDK

通过做一些实验&#xff0c;我发现手头提供JDK源代码来进行一些更改&#xff0c;使用它等等通常很有用。因此&#xff0c;我决定下载并编译该野兽。 显然&#xff0c;这花了我一些时间&#xff0c;尽管我最初的想法是&#xff0c;它应该和运行make命令一样简单&#xff1a;&…

unity中怎么在InspectorI面板加LOGO

转载于:https://www.cnblogs.com/unitySPK/p/7278925.html