这是我参与更文挑战的第12天,活动详情查看: 更文挑战html
[TOC]linux
maven是一个项目构建和管理的工具,提供了帮助管理 构建、文档、报告、依赖、scms、发布、分发的方法。能够方便的编译代码、进行依赖管理、管理二进制库等等。 maven的好处在于能够将项目过程规范化、自动化、高效化以及强大的可扩展性 利用maven自身及其插件还能够得到代码检查报告、单元测试覆盖率、实现持续集成等等。spring
用于指定存储jar包的路径,换句话说就是本地仓库地址,若是不设置默认是${user.home}/.m2/repository
。${user.home}是系统环境变量apache
<localRepository>E:/.m2</localRepository>
复制代码
表示是否使用交互模式,默认是true;若是设为false,那么当Maven须要用户进行输入的时候,它会使用一个默认值。windows
<interactiveMode>true</interactiveMode>
复制代码
表示Maven是否须要在离线模式下运行。若是构建系统须要在离线模式下运行,则为true,默认为false。当因为网络设置缘由或者安全因素,构建服务器不能链接远程仓库的时候,咱们就能够设置成false,这样安全安全
<offline>false</offline>
复制代码
pluginGroup
列表。默认maven中有org.apache.maven.plugins
和org.codehaus.mojo
两个pluginGroup
。表示当经过plugin的前缀来解析plugin的时候到哪里寻找。pluginGroup元素指定的是plugin的groupIdpluginGroups
里pluginGroup
列表和配置中artifactId进行一一匹配。匹配到下载。这里若是出现重复也不要紧,咱们使用的时候使用对了就好了。<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
复制代码
其下面能够定义一系列的proxy子元素,表示Maven在进行联网时须要使用到的代理。当设置了多个代理的时候第一个标记active为true的代理将会被使用服务器
<proxies>
<!--代理元素包含配置代理时须要的信息-->
<proxy>
<!--代理的惟必定义符,用来区分不一样的代理元素。-->
<id>myproxy</id>
<!--该代理是不是激活的那个。true则激活代理。当咱们声明了一组代理,而某个时候只须要激活一个代理的时候,该元素就能够派上用处。 -->
<active>true</active>
<!--代理的协议。 协议://主机名:端口,分隔成离散的元素以方便配置。-->
<protocol>http</protocol>
<!--代理的主机名。协议://主机名:端口,分隔成离散的元素以方便配置。 -->
<host>proxy.somewhere.com</host>
<!--代理的端口。协议://主机名:端口,分隔成离散的元素以方便配置。 -->
<port>8080</port>
<!--代理的用户名,用户名和密码表示代理服务器认证的登陆名和密码。 -->
<username>proxyuser</username>
<!--代理的密码,用户名和密码表示代理服务器认证的登陆名和密码。 -->
<password>somepassword</password>
<!--不应被代理的主机名列表。该列表的分隔符由代理服务器指定;例子中使用了竖线分隔符,使用逗号分隔也很常见。-->
<nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
</proxy>
</proxies>
复制代码
<servers>
<!--服务器元素包含配置服务器时须要的信息 -->
<server>
<!--这是server的id(注意不是用户登录的id),该id与distributionManagement中repository元素的id相匹配。-->
<id>server001</id>
<!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所须要的登陆名和密码。 -->
<username>my_login</username>
<!--鉴权密码 。鉴权用户名和鉴权密码表示服务器认证所须要的登陆名和密码。密码加密功能已被添加到2.1.0 +。详情请访问密码加密页面-->
<password>my_password</password>
<!--鉴权时使用的私钥位置。和前两个元素相似,私钥位置和私钥密码指定了一个私钥的路径(默认是${user.home}/.ssh/id_dsa)以及若是须要的话,一个密语。未来passphrase和password元素可能会被提取到外部,但目前它们必须在settings.xml文件以纯文本的形式声明。 -->
<privateKey>${usr.home}/.ssh/id_dsa</privateKey>
<!--鉴权时使用的私钥密码。-->
<passphrase>some_passphrase</passphrase>
<!--文件被建立时的权限。若是在部署的时候会建立一个仓库文件或者目录,这时候就可使用权限(permission)。这两个元素合法的值是一个三位数字,其对应了unix文件系统的权限,如664,或者775。 -->
<filePermissions>664</filePermissions>
<!--目录被建立时的权限。 -->
<directoryPermissions>775</directoryPermissions>
</server>
</servers>
复制代码
<distributionManagement>
<repository>
<id>release-repository</id>
<name>Release Repository</name>
<url>http://www.myrepository.com/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshot-repository</id>
<name>Snapshot Repository</name>
<url>http://www.myrepository.com/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
复制代码
上面配置了SNAPSHOT包的上传路径和RELEASE包的上传远程地址,可是咱们的这个远程地址有权限,最基本的就是须要帐号和密码。这个时候咱们不能暴露在项目中,咱们就能够在maven的setting中设置了,就是经过servers标签实现,markdown
<servers>
<server>
<id>snapshot-repository</id>
<username>snapshot</username>
<password>123456</password>
</server>
<server>
<id>release-repository</id>
<username>release</username>
<password>123456</password>
</server>
</servers>
复制代码
注意一点两边的id必须匹配才能够。 maven对密码进行加密处理网络
id:是用来区别mirror的,全部的mirror不能有相同的idssh
mirrorOf:用来表示该mirror是关联的哪个仓库,其值为其关联仓库的id。当要同时关联多个仓库时,这多个仓库之间能够用逗号隔开;当要关联全部的仓库时,可使用“”表示;当要关联除某一个仓库之外的其余全部仓库时,能够表示为“,!repositoryId”;当要关联不是localhost或用file请求的仓库时,能够表示为“external:*”。
url:表示该镜像的url。当Maven在创建系统的时候就会使用这个url来链接到咱们的远程仓库。
<mirrors>
<!--给定仓库的下载镜像。 -->
<mirror>
<!--该镜像的惟一标识符。id用来区分不一样的mirror元素。 -->
<id>planetmirror.com</id>
<!--镜像名称 -->
<name>PlanetMirror Australia</name>
<!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。 -->
<url>http://downloads.planetmirror.com/pub/maven2</url>
<!--被镜像的服务器的id。例如,若是咱们要设置了一个Maven中央仓库(http://repo.maven.apache.org/maven2/)的镜像,就须要将该元素设置成central。这必须和中央仓库的id central彻底一致。-->
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
复制代码
针对于特定项目的profile配置咱们能够定义在该项目的pom.xml中。
针对于特定用户的profile配置,咱们能够在用户的settings.xml文件中定义profile。该文件在用户家目录下的“.m2”目录下。
全局的profile配置。全局的profile是定义在Maven安装目录下的“conf/settings.xml”文件中的
```
<profiles>
<profile>
<id>zxh1</id>
<properties>
<zxhtom>single</zxhtom>
</properties>
</profile>
<profile>
<id>zxh2</id>
<properties>
<zxhtom>double</zxhtom>
</properties>
</profile>
<profiles>
```
+ 环境激活
在部署是符合这些环境要求的电脑则会获取到该profile的配置。这样咱们windows上配置和Linux上就不一样了。
```
<activation>
<os>
<!--激活profile的操做系统的名字 -->
<name>Windows 7</name>
<!--激活profile的操做系统所属家族(如 'windows') -->
<family>Windows</family>
<!--激活profile的操做系统体系结构 -->
<arch>x64</arch>
<!--激活profile的操做系统版本-->
<version>x.x.x..</version>
</os>
</activation>
```
+ 默认激活
* activeByDefault激活
下面的配置在咱们部署是没有指定profile时,zxh1这个profile就会成为默认的profile,若是咱们指定了那么zxh1就不会被启用。这里要注意这里是不启用。和后面的activeProfiles激活不一样。
```
<profiles>
<profile>
<id>zxh1</id>
<properties>
<zxhtom>single</zxhtom>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>zxh2</id>
<properties>
<zxhtom>double</zxhtom>
</properties>
</profile>
</profiles>
```
* activeProfiles激活
以下图中咱们定义zxh1为激活状态,另外咱们若是在经过参数或者其余条件激活了zxh2,这里zxh1和zxh2都是出于激活的,并不像activeByDefault激活那样直接中止了。而是二者的覆盖值合并。
```
<profiles>
<profile>
<id>zxh1</id>
<properties>
<zxhtom>single</zxhtom>
</properties>
</profile>
<profile>
<id>zxh2</id>
<properties>
<zxhtom>double</zxhtom>
</properties>
</profile>
<profiles>
<activeProfiles>
<activeProfile>zxh1</activeProfile>
</activeProfiles>
```
档以下在activeProfiles中配置了多个profile是,maven选择的是后者覆盖合并前者的方式,也就是将zxh1和zxh2合并,相同值去后者的值。
```
<profiles>
<profile>
<id>zxh1</id>
<properties>
<zxhtom>single</zxhtom>
</properties>
</profile>
<profile>
<id>zxh2</id>
<properties>
<zxhtom>double</zxhtom>
</properties>
</profile>
<profiles>
<activeProfiles>
<activeProfile>zxh1</activeProfile>
<activeProfile>zxh2</activeProfile>
</activeProfiles>
```
+ 文件激活
```
<activation>
<file>
<!--若是指定的文件存在,则激活profile。 -->
<exists>${basedir}/file2.properties</exists>
<!--若是指定的文件不存在,则激活profile。-->
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
```
复制代码