怎樣給公司定義一份完美的maven parent pom 文件

parent pom 定義你的項目模型,包括構建方式,項目環境,項目依賴,輸出JavaDoc,發佈source源碼等等,怎樣去編寫一份parent pom,這裏是一個現成的並正在某些項目中使用到的:點擊查看GitHub源碼

peaceful-basic-platform

A best global parent pom file , you can use it in jar or war project as your maven parent pom setting

<parent>
        <groupId>com.peaceful</groupId>
        <artifactId>peaceful-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
</parent> 

peaceful-parent

The basic configuration for build setting

  1. project build coding:UTF-8
  2. maven repositories:repo2
  3. default profiles: devtestproduct. The pom think project should has three running env or build env:dev、test、product. you can specify the environment by :

    mvn -Penv[test][product] compile[deploy][jetty:run]

The default env is dev, you can get the env value in pom by ${project.environment} and in Java code by invoke Application.getRunningMode()

setting build plugin

  1. buildnumber-maven-plugin:1.3 phase:validate desc:use timestamp as build version,you can get the version value by ${timestamp}
    in pom.xml and get the value in Java code by invoke Application.getBuildVersion()
  2. maven-jar-plugin:2.6
  3. maven-compiler-plugin:3.3
  4. maven-war-plugin:2.0.2
  5. maven-resources-plugin:2.7
  6. maven-source-plugin:2.4 phase:deploy
  7. maven-javadoc-plugin:2.9.1 phase:deploy
  8. maven-surefire-plugin:2.7 desc: default skip test
  9. yuicompressor-maven-plugin:1.5.0 desc:compress style file: .js .css
  10. jetty-maven-plugin:8.1.8.v20121106 desc: start web project in jetty, default port 8888,you can change web port in your pom to override Settings


setting dependencies

  1. log:slf4j log4j perf4j
  2. test:junit
  3. common tools:guava、commons-lang3、httpclient
  4. json:fastjson
  5. web:jstl、javaee-api
  6. db:mysql、c3p0
  7. framework:spring、springMvc、mybatis

peaceful-common-utils

Cooperate with the parent pom configuration files, can read building basic information, such as building time, version number, running environment of the project

The parent pom define 3 kinds of profile:devtestproduct。If your project use the pom as parent pom,you need add peaceful-common-utils dependency in your pom file.

<dependency>
    <groupId>com.peaceful</groupId>
    <artifactId>peaceful-common-utils</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

The peaceful-common-utils will read your build info into application.properties.

get build version

Application.getVersion()

get running mode

Application.getRunningMode()
...
Application.isTest()
Application.isProduct()
Application.isDev() 

get Running time

# you need invoke Application.loadToJVM() when your application start
Application.getRunningTime()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章