<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    qileilove

    blog已經轉移至github,大家請訪問 http://qaseven.github.io/

    maven常用插件配置和使用

    本文主要是介紹maven的幾個常見第三方插件(cobertura、findbugs、source、assembly、插件開發)配置和使用,接http://trinea.iteye.com/blog/1290898

     

    maven本質上是一個插件框架,它的所有工作都交給插件來做,每個插件可以有多個goal

    除了自帶的插件之外還有很多比較成熟的第三方插件,我們也很容易上手進行簡單的插件開發,下面一一介紹

     

    1 自帶插件

    maven自帶的核心插件為Build plugins和Reporting plugins。

    mvn compile編譯源碼實際上就利用到了maven-compiler-plugin,其他phase也類似用到了相應的插件

    關于maven自帶的核心插件見:http://maven.apache.org/plugins/index.html

     

    2 第三方插件

    2.1 maven有很多成熟的第三方插件

    如jetty 對于web開發使用jetty作為容器

    native 編譯c和c++代碼

    sql 執行sql腳本

    其他更多見:http://maven.apache.org/plugins/index.html#Outside_The_Maven_Land

    下面具體介紹下單元測試覆蓋率插件cobertura、findbugs

     

    2.2 maven2的cobertura插件

    2.2.1 cobertura是一款用來計算java代碼測試覆蓋率的工具,基于jcoverage。能計算每個類、包、整個工程的行覆蓋率和分支覆蓋率以及代碼復雜度(Cyclomatic complexity)并生成html或xml形式的報告,讓用戶很方便的查看代碼的單元測試覆蓋率情況。cobertura的原理是通過對class文件進行插樁然后計算。

     

    2.2.2 maven2的cobertura插件介紹

    插件地址為http://mojo.codehaus.org/cobertura-maven-plugin/index.html

    a、首先在pom中添加配置如下

    Xml代碼  收藏代碼
    1. <reporting>  
    2.     <outputDirectory>target/site</outputDirectory>  
    3.     <plugins>  
    4.         <plugin>  
    5.             <groupId>org.codehaus.mojo</groupId>  
    6.             <artifactId>cobertura-maven-plugin</artifactId>  
    7.         </plugin>  
    8.     </plugins>    
    9. </reporting>   

    b、運行goal

    到項目根目錄下運行mvn cobertura:cobertura 將會插樁class文件、測試、生成覆蓋率報告

    cobertura支持的goal如下

    c、在target\site\cobertura目錄下生成報告文件,打開index.html可以查看具體報告

    mvn cobertura:cobertura執行前會執行test phase,即執行單側代碼

     

    2.3 maven2的findbugs插件

    2.3.1 findbugs是靜態檢查java代碼的工具,根據一些bugs的表達式檢查代碼中的bugs,可以自定義檢查規則

     

    2.3.2 maven2的findbugs插件介紹

    插件地址為http://mojo.codehaus.org/findbugs-maven-plugin/index.html

    a、首先在pom中添加配置如下

    不同goal的配置略有不同,可自己調整,以下介紹的是mvn findbugs:findbugs的配置

    Xml代碼  收藏代碼
    1. <reporting>  
    2.     <plugins>  
    3.       <plugin>  
    4.         <groupId>org.codehaus.mojo</groupId>  
    5.         <artifactId>findbugs-maven-plugin</artifactId>  
    6.         <version>2.3.1</version>  
    7.       </plugin>  
    8.     </plugins>  
    9. </reporting>  

    b、運行goal

    到項目根目錄下運行mvn findbugs:findbugs將會開始檢查,并生成bugs報告

    findbugs支持的goal如下

    Xml代碼  收藏代碼
    1. findbugs:check  
    2.   Fail the build if there were any FindBugs violations in the source code. An  
    3.   XML report is put out by default in the target directory with the errors. To  
    4.   see more documentation about FindBugs' options, please see the FindBugs  
    5.   Manual..  
    6.   
    7. findbugs:findbugs  
    8.   Generates a FindBugs Report when the site plugin is run. The HTML report is  
    9.   generated for site commands only.  
    10.   
    11. findbugs:gui  
    12.   Launch the Findbugs GUI. It will use all the parameters in the POM fle.  
    13.   
    14. findbugs:help  
    15.   Display help information on findbugs-maven-plugin.  
    16.   Call  
    17.     mvn findbugs:help -Ddetail=true -Dgoal=<goal-name>  
    18.   to display parameter details.  

    c、在target\site\findbugs目錄下生成報告文件,打開index.html可以查看具體報告

    mvn findbugs:findbugs綁定到了compile phase,即在編譯時自動檢查

    http://qa.taobao.com/?p=4206

     

    2.4 maven的source插件

    2.4.1 source插件用來將工程打包成帶源代碼的jar包

    2.4.2 maven2的source插件介紹

    Xml代碼  收藏代碼
    1. <build>  
    2.     <plugins>  
    3.       <plugin>  
    4.         <groupId>org.apache.maven.plugins</groupId>  
    5.         <artifactId>maven-source-plugin</artifactId>  
    6.         <version>2.1.2</version>  
    7.         <executions>  
    8.           <execution>  
    9.             <id>attach-sources</id>  
    10.             <phase>verify</phase>  
    11.             <goals>  
    12.               <goal>jar-no-fork</goal>  
    13.             </goals>  
    14.           </execution>  
    15.         </executions>  
    16.       </plugin>  
    17.     </plugins>  
    18. </build>  

    直接運行mvn clean install會在target下打出兩個包,帶***-sources.jar的為源碼包

     

    2.5 maven的assembly插件

    2.5.1 assembly插件可用來將工程依賴的jar包和工程都打成一個jar打包

    2.5.2 maven2的assembly插件pom配置如下

    Xml代碼  收藏代碼
    1. <build>  
    2.     <plugins>         
    3.       <plugin>  
    4.         <artifactId>maven-assembly-plugin</artifactId>  
    5.         <configuration>  
    6.           <descriptorRefs>  
    7.             <descriptorRef>jar-with-dependencies</descriptorRef>  
    8.           </descriptorRefs>  
    9.         </configuration>  
    10.       </plugin>  
    11.     </plugins>  
    12. </build>  

    直接運行mvn assembly:assembly會在target下出現***-with-dependencies.jar的jar包

     

    2.6 插件開發

    maven的插件開發相當簡單,可以參考http://trinea.iteye.com/blog/1171957

    posted on 2014-03-31 17:29 順其自然EVO 閱讀(454) 評論(0)  編輯  收藏 所屬分類: maven

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿(55)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 在线免费观看a级片| 免费无码看av的网站| 免费成人在线视频观看| 国产免费一区二区视频| 亚洲综合精品香蕉久久网| 国产亚洲综合色就色| 亚洲黄色网址大全| 2017亚洲男人天堂一| 欧美日韩亚洲精品| 你懂的网址免费国产| 西西大胆无码视频免费| 激情97综合亚洲色婷婷五 | 99爱在线观看免费完整版| 成年免费大片黄在线观看岛国| 亚洲毛片在线免费观看| www成人免费视频| 国产一卡二卡四卡免费| 精品国产亚洲一区二区在线观看 | 无人在线观看完整免费版视频| 亚洲乱码一二三四区国产| h视频免费高清在线观看| 成人无码区免费视频观看| 在线亚洲精品福利网址导航| 大地资源在线资源免费观看| 亚洲成aⅴ人片久青草影院| 久久久久精品国产亚洲AV无码| 久草免费福利视频| 亚洲欧洲另类春色校园小说| a级毛片在线视频免费观看| 91大神亚洲影视在线| 日本不卡在线观看免费v| 亚洲w码欧洲s码免费| 国产免费资源高清小视频在线观看| 亚洲春黄在线观看| 精品国产免费观看一区| a在线视频免费观看| 亚洲六月丁香婷婷综合| 国产亚洲?V无码?V男人的天堂| 2021在线永久免费视频| 亚洲bt加勒比一区二区| 国产精品小视频免费无限app|