Maven| Maven相关概念

Maven仓库加载

Maven 远程仓库默认配置文件:
$MAVEN_HOME/lib/maven-model-builder-3.3.3.jar
文件:org\apache\maven\model\pom-4.0.0.xml
例如:
博主的是在D:\ProgramFiles\apache-maven-3.5.0\lib\maven-model-builder-3.5.0.jar
文件:org\apache\maven\model\pom-4.0.0.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
	license agreements. See the NOTICE file distributed with this work for additional 
	information regarding copyright ownership. The ASF licenses this file to 
	you under the Apache License, Version 2.0 (the "License"); you may not use 
	this file except in compliance with the License. You may obtain a copy of 
	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
	by applicable law or agreed to in writing, software distributed under the 
	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
	OF ANY KIND, either express or implied. See the License for the specific 
	language governing permissions and limitations under the License. -->

<!-- START SNIPPET: superpom -->
<project>
	<modelVersion>4.0.0</modelVersion>

	<repositories>
		<repository>
			<id>central</id>
			<name>Central Repository</name>
			<url>https://repo.maven.apache.org/maven2</url>
			<layout>default</layout>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>

	<pluginRepositories>
		<pluginRepository>
			<id>central</id>
			<name>Central Repository</name>
			<url>https://repo.maven.apache.org/maven2</url>
			<layout>default</layout>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<releases>
				<updatePolicy>never</updatePolicy>
			</releases>
		</pluginRepository>
	</pluginRepositories>

	<build>
		<directory>${project.basedir}/target</directory>
		<outputDirectory>${project.build.directory}/classes</outputDirectory>
		<finalName>${project.artifactId}-${project.version}</finalName>
		<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
		<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
		<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
		<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
		<resources>
			<resource>
				<directory>${project.basedir}/src/main/resources</directory>
			</resource>
		</resources>
		<testResources>
			<testResource>
				<directory>${project.basedir}/src/test/resources</directory>
			</testResource>
		</testResources>
		<pluginManagement>
			<!-- NOTE: These plugins will be removed from future versions of the super 
				POM -->
			<!-- They are kept for the moment as they are very unlikely to conflict 
				with lifecycle mappings (MNG-4453) -->
			<plugins>
				<plugin>
					<artifactId>maven-antrun-plugin</artifactId>
					<version>1.3</version>
				</plugin>
				<plugin>
					<artifactId>maven-assembly-plugin</artifactId>
					<version>2.2-beta-5</version>
				</plugin>
				<plugin>
					<artifactId>maven-dependency-plugin</artifactId>
					<version>2.8</version>
				</plugin>
				<plugin>
					<artifactId>maven-release-plugin</artifactId>
					<version>2.3.2</version>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>

	<reporting>
		<outputDirectory>${project.build.directory}/site</outputDirectory>
	</reporting>

	<profiles>
		<!-- NOTE: The release profile will be removed from future versions of 
			the super POM -->
		<profile>
			<id>release-profile</id>

			<activation>
				<property>
					<name>performRelease</name>
					<value>true</value>
				</property>
			</activation>

			<build>
				<plugins>
					<plugin>
						<inherited>true</inherited>
						<artifactId>maven-source-plugin</artifactId>
						<executions>
							<execution>
								<id>attach-sources</id>
								<goals>
									<goal>jar</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<inherited>true</inherited>
						<artifactId>maven-javadoc-plugin</artifactId>
						<executions>
							<execution>
								<id>attach-javadocs</id>
								<goals>
									<goal>jar</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<inherited>true</inherited>
						<artifactId>maven-deploy-plugin</artifactId>
						<configuration>
							<updateReleaseInfo>true</updateReleaseInfo>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>

</project>
<!-- END SNIPPET: superpom -->

Maven 依赖特性

依赖选择:(最短路径原则和最先申明原则)
(一)选p2 ,(二)选p3

(一)
A-> B -> C ->D ->X ( P1 )
A -> D -> X ( P2 )
(二)
A -> B ->X ( P3 )
A -> C ->X ( P4 )
依赖传递依赖特性:
这里写图片描述


Maven 聚合与继承特性

在父的管理模块统一聚合管理子项目

	<!-- 配置模块聚合子模块管理: 比如所有的模块clean,install之类的操作 -->
	<modules>
		<module>../yves-dao</module>
		<module>../yves-service</module>
		<module>../yves-web</module>
	</modules>
	
	<!-- 依赖总管理 -->
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
				<version>3.3.0</version>
			</dependency>
			...
			
		</dependencies>
	</dependencyManagement>

子项目中可以继承父项目里面的依赖

	<!-- maven的继承 : 查看项目yves-parent查看相应配置 -->
	<parent>
		<groupId>cn.com.yves</groupId>
		<artifactId>yves-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<relativePath>../yves-parent/pom.xml</relativePath>  <!-- 配置父pom.xml的相对路径 -->
	</parent>

maven依赖的聚合依赖例子:
聚合和继承的例子

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值