setting文件详解

您所在的位置:网站首页 cam文件是干什么的 setting文件详解

setting文件详解

2024-03-06 11:05| 来源: 网络整理| 查看: 265

记录maven配置 mirrorOf 坑_sapphire7999的博客-CSDN博客_maven mirrorof对应仓库id 问题

——————————————————————————————————————

最近在学习maven的相关知识,自己利用nexus3服务搭建了一个maven的私有仓库。测试一下的maven的镜像地址目前都有效:

(最快) http://maven.ibiblio.org/maven2/ http://central.maven.org/maven2/ http://repo1.maven.apache.org/maven2/ http://repo1.maven.org/maven2/ http://mirrors.ibiblio.org/pub/mirrors/maven2/ https://repository.jboss.org/nexus/content/groups/public/ http://repo2.maven.org/maven2/ 在更换地址后,建议点击nexus的rebuild index按钮。 —————————————————————————————————————

settings.xml文件是干什么的,为什么要配置它呢? 从settings.xml的文件名就可以看出,它是用来设置maven参数的配置文件。并且,settings.xml是maven的全局配置文件。而pom.xml文件是所在项目的局部配置。 Settings.xml中包含类似本地仓储位置、修改远程仓储服务器、认证信息等配置。 settings.xml文件位置

settings.xml文件一般存在于两个位置: 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: user.home/.m2/settings.xmlnote:用户配置优先于全局配置。user.home/.m2/settings.xmlnote:用户配置优先于全局配置。 {user.home} 和和所有其他系统属性只能在3.0+版本上使用。请注意windows和Linux使用变量的区别。

配置优先级

需要注意的是:局部配置优先于全局配置。 配置优先级从高到低:pom.xml> user settings > global settings 如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。

settings.xml元素详解 顶级元素概览

下面列举了settings.xml中的顶级元素

LocalRepository

作用:该值表示构建系统本地仓库的路径。 其默认值:~/.m2/repository。

${user.home}/.m2/repository InteractiveMode

作用:表示maven是否需要和用户交互以获得输入。 如果maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。

true UsePluginRegistry

作用:maven是否需要使用plugin-registry.xml文件来管理插件版本。 如果需要让maven使用文件~/.m2/plugin-registry.xml来管理插件版本,则设为true。默认为false。

false Offline

作用:表示maven是否需要在离线模式下运行。 如果构建系统需要在离线模式下运行,则为true,默认为false。 当由于网络设置原因或者安全因素,构建服务器不能连接远程仓库的时候,该配置就十分有用。

false PluginGroups

作用:当插件的组织id(groupId)没有显式提供时,供搜寻插件组织Id(groupId)的列表。 该元素包含一个pluginGroup元素列表,每个子元素包含了一个组织Id(groupId)。 当我们使用某个插件,并且没有在命令行为其提供组织Id(groupId)的时候,Maven就会使用该列表。默认情况下该列表包含了org.apache.maven.plugins和org.codehaus.mojo。

... org.codehaus.mojo ... Servers

作用:一般,仓库的下载和部署是在pom.xml文件中的repositories和distributionManagement元素中定义的。然而,一般类似用户名、密码(有些仓库访问是需要安全认证的)等信息不应该在pom.xml文件中配置,这些信息可以配置在settings.xml中。

... server001 my_login my_password ${usr.home}/.ssh/id_dsa some_passphrase 664 775 ... Mirrors

作用:为仓库列表配置的下载镜像列表。

... planetmirror.com PlanetMirror Australia http://downloads.planetmirror.com/pub/maven2 central ... Proxies

作用:用来配置不同的代理。

... myproxy true http proxy.somewhere.com 8080 proxyuser somepassword *.google.com|ibiblio.org ... Profiles

作用:根据环境参数来调整构建配置的列表。settings.xml中的profile元素是pom.xml中profile元素的裁剪版本。 它包含了id、activation、repositories、pluginRepositories和 properties元素。这里的profile元素只包含这五个子元素是因为这里只关心构建系统这个整体(这正是settings.xml文件的角色定位),而非单独的项目对象模型设置。如果一个settings.xml中的profile被激活,它的值会覆盖任何其它定义在pom.xml中带有相同id的profile。

... test ... Activation

作用:自动触发profile的条件逻辑。 如pom.xml中的profile一样,profile的作用在于它能够在某些特定的环境中自动使用某些特定的值;这些环境通过activation元素指定。activation元素并不是激活profile的唯一方式。settings.xml文件中的activeProfile元素可以包含profile的id。profile也可以通过在命令行,使用-P标记和逗号分隔的列表来显式的激活(如,-P test)。

false 1.5 Windows XP Windows x86 5.1.2600 mavenVersion 2.0.3 ${basedir}/file2.properties ${basedir}/file1.properties

注:在maven工程的pom.xml所在目录下执行mvn help:active-profiles命令可以查看中央仓储的profile是否在工程中生效。

properties

作用:对应profile的扩展属性列表。 maven属性和ant中的属性一样,可以用来存放一些值。这些值可以在pom.xml中的任何地方使用标记${X}来使用,这里X是指属性的名称。属性有五种不同的形式,并且都能在settings.xml文件中访问。

${user.home}/our-project

注:如果该profile被激活,则可以在pom.xml中使用${user.install}。

Repositories

作用:远程仓库列表,它是maven用来填充构建系统本地仓库所使用的一组远程仓库。

codehausSnapshots Codehaus Snapshots false always warn http://snapshots.maven.codehaus.org/maven2 default pluginRepositories

作用:发现插件的远程仓库列表。 和repository类似,只是repository是管理jar包依赖的仓库,pluginRepositories则是管理插件的仓库。 maven插件是一种特殊类型的构件。由于这个原因,插件仓库独立于其它仓库。pluginRepositories元素的结构和repositories元素的结构类似。每个pluginRepository元素指定一个Maven可以用来寻找新插件的远程地址。

ActiveProfiles

作用:手动激活profiles的列表,按照profile被应用的顺序定义activeProfile。 该元素包含了一组activeProfile元素,每个activeProfile都含有一个profile id。任何在activeProfile中定义的profile id,不论环境设置如何,其对应的 profile都会被激活。如果没有匹配的profile,则什么都不会发生。 例如,env-test是一个activeProfile,则在pom.xml(或者profile.xml)中对应id的profile会被激活。如果运行过程中找不到这样一个profile,Maven则会像往常一样运行。

... env-test ...

至此,maven settings.xml中的标签都讲解完毕,希望对大家有所帮助。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3