Maven 功能及其语法


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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值