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.pswp.cn/news/371590.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/371590.shtml
英文地址,請注明出處:http://en.pswp.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