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
project build coding:
UTF-8
maven repositories:
repo2
default profiles:
dev
、test
、product
. 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
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 invokeApplication.getBuildVersion()
maven-jar-plugin:2.6
maven-compiler-plugin:3.3
maven-war-plugin:2.0.2
maven-resources-plugin:2.7
maven-source-plugin:2.4 phase:deploy
maven-javadoc-plugin:2.9.1 phase:deploy
maven-surefire-plugin:2.7 desc: default skip test
yuicompressor-maven-plugin:1.5.0 desc:compress style file: .js .css
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
<properties> <jetty.stop.port>9999</jetty.stop.port> <jetty.run.port>8888</jetty.run.port> </properties>
setting dependencies
log:slf4j log4j perf4j
test:junit
common tools:guava、commons-lang3、httpclient
json:fastjson
web:jstl、javaee-api
db:mysql、c3p0
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:dev
、test
、product
。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()