Maven 功能及其语法

来源:互联网 发布:mac 电影 little boy 编辑:程序博客网 时间:2024/06/01 09:35


maven中有很多语法,这里我们说说一些常用的语法


依赖

<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>4.3.3.Final</version></dependency>

屏蔽依赖传递

<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>4.3.3.Final</version><exclusions><groupId>dom4j</groupId><artifactId>dom4j</artifactId><!--无需再声明版本--></exclusions></dependency>

构建有效范围

<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>4.3.3.Final</version><scope>test</scope><!--scope标签声明为test,则依赖不会被传递。默认值是之compile,依赖会被传递--></dependency>

继承

<parent><!--指明父项目的坐标--><groupId>cn.wp.test</groupId><artifactId>parent</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../parent/pom.xml</relativePath></parent>

强制性继承(父pom.xml文件中直接添加依赖)

<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>4.3.3.Final</version></dependency>

选择性继承(父pom.xml文件中添加依赖管理,子项目选择继承)

父项目<dependencyManagement><dependencies><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>4.3.3.Final</version></dependency></dependencies></dependencyManagement>子项目<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><!--无需再声明版本--></dependency>

聚合

<modules><module>../main/pom.xml</module><!--指明模块项目的路径--><module>../model1/pom.xml</module><!--指明模块项目的路径--></modules>

发布

配置项目pom.xml(声明发布的仓库)

<distributionManagement><repository><!-- 发布版本发布仓库 --><id>wepu-releases</id><name>wepu-releases</name><url>http://192.168.41.191:8081/nexus/content/repositories/releases/</url></repository><snapshotRepository><!-- 快照版本发布仓库 --><id>wepu-snapshots</id><name>wepu-snapshots</name><url>http://192.168.41.191:8081/nexus/content/repositories/snapshots/</url></snapshotRepository></distributionManagement>

配置maven 工作区中 settings.xml(发布的权限)

<servers><server><id>wepu-releases</id><username>deployment</username><password>deployment123</password></server><server><id>wepu-snapshots</id><username>deployment</username><password>deployment123</password></server></servers>

配置 nexus 镜像

配置maven 工作区中 settings.xml

<mirrors><mirror><id>central</id><mirrorOf>*</mirrorOf> <!-- 对所有仓库镜像 --><name>central mirror</name><url>http://192.168.41.191:8081/nexus/content/groups/public/</url></mirror></mirrors>
0 0