maven-pom.xml配置
来源:互联网 发布:js 对象 remove 编辑:程序博客网 时间:2024/06/05 10:03
pom作为项目对象模型。通过xml表示maven项目,使用pom.xml来实现。主要描述了项目:包括配置文件;开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的url,项目的依赖性,以及其他所有的项目相关因素。
快速察看:
<project>
<modelVersion>4.0.0</modelVersion>
<!--maven2.0必须是这样写,现在是maven2唯一支持的版本-->
<!-- 基础设置 -->
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>...</packaging>
<name>...</name>
<url>...</url>
<dependencies>...</dependencies>
<parent>...</parent>
<dependencyManagement>...</dependencyManagement>
<modules>...</modules>
<properties>...</properties>
<!--构建设置 -->
<build>...</build>
<reporting>...</reporting>
<!-- 更多项目信息 -->
<name>...</name>
<description>...</description>
<url>...</url>
<inceptionYear>...</inceptionYear>
<licenses>...</licenses>
<organization>...</organization>
<developers>...</developers>
<contributors>...</contributors>
<!-- 环境设置-->
<issueManagement>...</issueManagement>
<ciManagement>...</ciManagement>
<mailingLists>...</mailingLists>
<scm>...</scm>
<prerequisites>...</prerequisites>
<repositories>...</repositories>
<pluginRepositories>...</pluginRepositories>
<distributionManagement>...</distributionManagement>
<profiles>...</profiles>
</project>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion><groupId>MavenTestPro</groupId> <!-- 项目或者组织的唯一标志,并且配置时生成的路径也由此产生 -->
<artifactId>mavenTest</artifactId> <!-- 项目的通用名称 -->
<version>0.0.1-SNAPSHOT</version> <!-- 项目的版本 -->
<packaging>war</packaging> <!-- 打包的机制 -->
<!-- #######################依赖关系######################
<dependencies>
<dependency>
<groupId>/junit</groupId>
<artifactId>/junit</artifactId>
<version>/4.0</version>
<type>/jar</type> 响应的依赖产品包形式
<scope>/test</scope> 用于限制相应的依赖范围,包含:compile/provide/runtime/test/system/systemPath
<optional>true</optional> 标注可选,当项目自身也是依赖时,用于连续依赖时使用,默认为fause,即子项目默认都继承
</dependency>
-->
<!-- 独占性,告诉maven你只能包括指定的项目,不包括相关的依赖,用于解决版本冲突问题
<dependency>
<groupId></groupId>
<artifactId>/maven-embedder</artifactId>
<version></version>
<exclusions>
<exclusion>
<groupId></groupId>
<artifactId>/maven-core</artifactId> 表示项目maven-embedder需要项目maven-core,但是我们不想引用maven-core
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
-->
<!-- 继承关系,maven的项目继承
如果一个工程是parent或者aggregation(即mutil-module的)的,那么必须在packing赋值为pom,child工程从parent继承的包括:dependencies,developers,contributors,plugin lists,reports lists,plugin execution with matching ids,plugin configuration
<modelVersion>/4.0.0</modelVersion>
<groupId>/org.codehaus.mojo</groupId>
<artifactId>/my-parent</artifactId>
<version>/2.0</version>
<packaging>/pom</packaging>
</project>
-->
<!-- 子项目配置 -->
<!-- <project>
<modelVersion>/4.0.0</modelVersion>
<parent>
<groupId>/org.codehaus.mojo</groupId>
<artifactId>/my-parent</artifactId>
<version>/2.0</version>
<relativePath>../my-parent</relativePath>
</parent>
<artifactId>/my-parent</artifactId>
</project>
-->
</project>
<!-- 用于父项目配置共同的依赖关系,主要配置依赖包相同因素,如版本,scope;dependencyManagement:是用于帮助管理chidren的dependencies的
<dependencyManagement>scope</dependencyManagement>
-->
<!-- 合成:一个项目有多个模块,也叫多重模块,或者合成项目
<project>
<modelVersion>/4.0.0</modelVersion>
<groupId>/org.codehaus.mojo</groupId>
<artifactId>/my-parent</artifactId>
<version>/2.0</version>
<modules>
<module>my-project1</module>
<module>my-project1</module>
</modules>
</project>
-->
<!-- <properties></properties> properties:是为pom定义一些常量,在pom中的其它地方可以直接引用
<properties>
<file.encoding>UTF-8</file_encoding>
<Java.source.version>1.5</java_source_version>
<java.target.version>1.5</java_target_version>
</properties>
使用方式 如下 :${file.encoding}
- ->
<!-- #############build设置,主要用于编译设置,包括两个主要的元素,build和report############build主要分为两部分,基本元素和拓展元素集合
包括build和profile build
<project>
<build>。。</build>
<profiles>
<profile>
<build>。。</build>
</profile>
</profiles>
</project>
基本元素
<build>
<defaultGoal>install</defaultGoal> 定义默认的目标或者阶段。如install;必须跟命令行上的参数相同
<directory>>${basedir}/target</directory> 编译输出的目录,默认为$(basedir}/target,即项目根目录下的target
<finalname>${artifactId}-${version}</finalname> 生成最后的文件的样式,例如:默认为${artifactId}-${version}
<filters>
<filter>filters/filter1.properties</filter> 定义过滤,用于替换相应的属性文件,使用maven定义的属性,默认的filter目录是${basedir}/src/main/fiters/
</filters>
</build>
资源:你项目中需要指定的资源。如spring配置文件,log4j.properties;描述工程中资源的位置
<project>
<build>
...
<resources> resource的列表,用于包括所有的资源
<resource>
<targetPath>META-INF/plexus</targetPath> 指定目标路径,用于放置资源,用于build
<filtering>false</filtering> 是否替换资源中的属性placehold,build的过程需要找到它,并且将其放到targetPath下,默认的directory 是${basedir}/src/main /resources
<directory>${basedir}/src/main/plexus</directory> 资源所在的位置
<includes> 样式,包括那些资源
<include>configuration.xml</include>
</includes>
<excludes> 排除的资源
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<testResources> 测试资源列表
...
</testResources>
...
</build>
</project>
插件:在build时,执行的插件,比较有用的部分,如使用jdk 5.0编译等等
<project>
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.0</version>
<extensions>false</extensions> true or false,是否装载插件扩展。默认false
<inherited>true</inherited> true or false,是否此插件配置将会应用于poms,那些继承于此的项目;是否让子pom继承,ture or false 默认为true.
<configuration> 指定插件配置,通常用于私有不开源的plugin,
<classifier>test</classifier>
</configuration>
<dependencies>...</dependencies> 插件需要依赖的包,与pom基础的dependencies的结构和功能都相同,只是plugin的dependencies用于plugin,而pom的 denpendencies用于项目本身
<executions>...</executions> 用于配置execution目标,一个插件可以有多个目标
</plugin>
</plugins>
</build>
</project>
一个插件可以有多个目标
<plugin>
<artifactId>maven-antrun-plugin<artifactId>
<executions>
<execution>
<id>echodir</id> 规定execution 的唯一标志
<goals> 表示目标
<goal>run</goal>
<phase>verify</phase> 表示阶段,目标将会在什么阶段执行
<inherited>false</inherited> 和上面的元素一样,设置false maven将会拒绝执行继承给子插件
<configuration> 表示此执行的配置属性
<tasks>
<echo>Build Dir: ${project.build.directory}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
插件管理pluginManagement:插件管理以同样的方式包括插件元素,用于在特定的项目中配置。所有继承于此项目的子项目都能使用。主要定义插件的共同元素;pluginManagement的作用类似于denpendencyManagement,只是denpendencyManagement是用于管理项目jar包依赖,pluginManagement是用于管理plugin。
与pom build里的plugins区别是,这里的plugin是列出来,然后让子pom来决定是否引用。
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>pre-process-classes</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>pre-process</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
子pom引用方法:
在pom的build里的plugins引用:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
build里的directories:
<sourceDirectory>${basedir}/src/main/java<sourceDirectory>
<scriptSourceDirectory>${basedir}/src/main/scripts<scriptSourceDirectory>
<testSourceDirectory>${basedir}/src/test/java<testSourceDirectory>
<outputDirectory>${basedir}/target/classes<outputDirectory>
<testOutputDirectory>${basedir}/target/test-classes<testOutputDirectory>
...
<build>
Extensions表示需要扩展的插件,必须包括进相应的build路径,extensions是在build过程被激活的产品
<project>
<build>
...
<extensions>
<extension>
<groupId>org.apache.maven.wagon<groupId>
<artifactId>wagon-ftp<artifactId>
<version>1.0-alpha-3<version>
<extension>
<extensions>
...
<build>
<project>
-->
<!-- buildEnd -->
<!-- ##############Reporting用于在site阶段输出报表。特定的maven 插件能输出相应的定制和配置报表##############
reporting包含site生成阶段的一些元素,某些maven plugin可以生成reports并且在reporting下配置。例如javadoc,maven site等,在reporting下配置的report plugin的方法与build几乎一样,最不同的是build的plugin goals在executions下设置,而reporting的configures goals在reporttest。
<plugins>
<plugin>
<outputDirectory>/${basedir}/target/site</outputDirectory>
<artifactId>maven-project-info-reports-plugin</artifactId>
<reportSets>
<reportSet></reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
Report Sets用于配置不同的目标,应用于不同的报表
<reporting>
<plugins>
<plugin>
<reportSets>
<reportSet>
<id>sunlink</id>
<reports>
<report>javadoc</report>
<inherited>true</inherited>
<configuration>
<links>
<link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
</links>
</configuration>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
reporting里面的厄reportSets和build里面的executions的作用都是控制pom的不同粒度去控制build的过程,我们不单要配置plugins,还要配置那些plugins单独的goals
<!--
<name></name> 项目除了artifactId外,可以定义多个名称
<description></description> 项目描述
<url></url> 项目url
<inceptionYear></inceptionYear> 创始年份
-->
<!-- ############Licenses###########
列出本工程直接的licenses,而不要列出dependencies的licenses
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
-->
<!-- ############Organization配置组织信息###########
<organization>
<name>Codehaus Mojo</name>
<url>http://mojo.codehaus.org</url>
</organization>
-->
<!-- ##############Developers配置开发者信息#############
<developers>
<developer>
<id>eric</id>
<name>Eric</name>
<email>eredmond@codehaus.org</email>
<url>http://eric.propellors.net</url>
<organization>Codehaus</organization>
<organizationUrl>http://mojo.codehaus.orgorganization</organizationUrl>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>-6</timezone>
<properties>
<picUrl>http://tinyurl.com/prv4t</picUrl>
</properties>
</developer>
</developers> -->
<!-- Contributors
<contributors>
<contributor>
<name>Noelle</name>
<email>some.name@gmail.com</email>
<url>http://noellemarie.com</url>
<organization>Noelle Marie</organization>
<organizationUrl>http://noellemarie.com</organizationUrl>
<roles>
<role>tester</role>
</roles>
<timezone>-5</timezone>
<properties>
<gtalk>some.name@gmail.com</gtalk>
</properties>
</contributor>
</contributors>
-->
<!-- ###################环境设置###################
#####Issue Management:定义相关的bug跟踪系统,如bugzilla,testtrack,clearQuest等#####
<issueManagement>
<system>Bugzilla</system>
<url>http://127.0.0.1/bugzilla</url>
</issueManagement>
-->
<!--
###Continuous Integration Management(ciManagement)连续整合管理,基于triggers或者timings###
<ciManagement>
<system>continuum</system>
<url>http://127.0.0.1:8080/continuum</url>
<notifiers>
<notifier>
<type>mail</type>
<sendOnError>true</sendOnError>
<sendOnFailure>true</sendOnFailure>
<sendOnSuccess>false</sendOnSuccess>
<sendOnWarning>false</sendOnWarning>
<configuration>
<address>continuum@127.0.0.1</address>
</configuration>
</notifier>
</notifiers>
</ciManagement>
-->
<!-- #############Mailing Lists#############
<mailingLists>
<mailingList>
<name>User List</name>
<subscribe>user-subscribe@127.0.0.1</subscribe>
<unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe>
<post>user@127.0.0.1</post>
<archive>http://127.0.0.1/user/</archive>
<otherArchives>
<otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
</otherArchives>
</mailingList>
</mailingLists>
-->
<!-- ############SCM软件配置管理,如cvs 和svn############
<scm>
<connection>scm:svn:http://127.0.0.1/svn/my-project</connection>
<developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection>
<tag>HEAD</tag>
<url>http://127.0.0.1/websvn/my-project</url>
</scm>
-->
<!--
<prerequisites></prerequisites>
<repositories></repositories> 配置同setting.xml中的开发库
<pluginRepositories></pluginRepositories> 配置同 repositories
-->
<!-- ####<distributionManagement></distributionManagement>用于配置分发管理,配置相应的产品发布信息,主要用于发布,在执行mvn deploy后表示要发布的位置####
1 配置到文件系统
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>file://${basedir}/target/deploy</url>
</repository>
</distributionManagement>
2 使用ssh2配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>scp://sshserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
3 使用sftp配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>sftp://ftpserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
4 使用外在的ssh配置:编译扩展用于指定使用wagon外在ssh提供,用于提供你的文件到相应的远程服务器。
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>scpexe://sshserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>
5 使用ftp配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>ftp://ftpserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>
Url:是其他项目为了抓取本项目的pom’s artifact而指定的url,就是说告诉pom upload的地址也就是别人可以下载的地址。
status:这里的状态不要受到我们的设置,maven会自动设置project的状态,有效的值:none:没有声明状态,pom默认的;converted:本project是管理员从原先的maven版本convert到maven2的;partner:以前叫做synched,意思是与partner repository已经进行了同步;deployed:至今为止最经常的状态,意思是制品是从maven2 instance部署的,人工在命令行deploy的就会得到这个;verified:本制品已经经过验证,也就是已经定下来了最终版。
repository:声明deploy过程中current project会如何变成repository,说明部署到repository的信息。
id, name::唯一性的id,和可读性的name
uniqueVersion:指定是否产生一个唯一性的version number还是使用address里的其中version部分。true or false
url:说明location和transport protocol
layout:default或者legacy
-->
<!--repository 对应于你的开发库,用户信息通过settings.xml中的server取得,
Repositories:pom里面的仓库与setting.xml里的仓库功能是一样的。主要的区别在于,pom里的仓库是个性化的。比如一家大公司里的setting文件是公用 的,所有项目都用一个setting文件,但各个子项目却会引用不同的第三方库,所以就需要在pom里设置自己需要的仓库地址
repositories:要成为maven2的repository artifact,必须具有pom文件在$BASE_REPO/groupId/artifactId/version/artifactId-version.pom
BASE_REPO可以是本地,也可以是远程的。repository元素就是声明那些去查找的repositories
默认的central Maven repository在http://repo1.maven.org/maven2/
<repositories>
<repository>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
release和snapshots:是artifact的两种policies,pom可以选择那种政策有效
enable:本别指定两种类型是否可用,true or false
updatePolicy:说明更新发生的频率always 或者 never 或者 daily(默认的)或者 interval:X(X是分钟数)
checksumPolicy:当Maven的部署文件到仓库中,它也部署了相应的校验和文件。您可以选择忽略,失败,或缺少或不正确的校验和警告
插件仓库:
pluginRepositories:与Repositories具有类似的结构,只是Repositories是dependencies的home,而这个是plugins 的home。
-->
<profiles>
<profile>
<id>test</id>
<activation>...</activation>
<build>...</build>
<modules>...</modules>
<repositories>...</repositories>
<pluginRepositories>...</pluginRepositories>
<dependencies>...</dependencies>
<reporting>...</reporting>
<dependencyManagement>...</dependencyManagement>
<distributionManagement>...</distributionManagement>
</profile>
</profiles>
设置项目主函数:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cn.vicky.mainapp.App</mainClass>
</transformer>
</transformers
</configuration>
</execution>
</executions>
</plugin>
-->
- Maven pom.xml配置
- maven pom.xml 配置
- maven-pom.xml配置
- maven pom.xml配置
- maven pom.xml配置说明
- maven pom.xml jetty 配置
- Maven pom.xml 配置详解
- Maven pom.xml 配置详解
- maven pom.xml配置讲解
- Maven pom.xml 配置详解
- Maven pom.xml 配置详解
- Maven pom.xml 配置详解
- Maven pom.xml 配置详解
- Maven pom.xml配置详解
- maven pom.xml 文件配置
- Maven pom.xml配置详解
- Maven pom.xml 配置详解
- maven之pom.xml配置
- c语言练习之规范编写
- file.listFiles()按文件大小、名称、日期排序方法
- Codeforces Round #380 (Div. 2)C. Road to Cinema
- jmeter参数化的四种方法
- Java基础-IO流5 缓冲区
- maven-pom.xml配置
- Rails 重构: 利用 Service 优化 Fat Model
- Android背景添加渐变,描边,圆角的效果
- 安装Homebrew
- POJ 1703 Find them, Catch them 种类并查集
- 收藏了一些国内的android开发博客:
- SpingMVC常用注解
- 八大排序--归并排序
- 用JNI从C传递结构体到JAVA