maven 仓库配置
本地仓库和远程仓库;
本地仓库
默认是在~/.m2/repository/,~代表的是用户目录;
配置比较简单,只要在xml中配置如下:
<localRepository>E:/Data/Maven/repositorylocalRepository>
远程仓库
分为中央仓库和私服。默认是maven的中央仓库:https://mvnrepository.com/
远程仓库配置:
<repositories> <repository> <id>centralid> <name>Central Repositoryname> <url>https://repo.maven.apache.org/maven2url> <layout>defaultlayout> <snapshots> <enabled>falseenabled> snapshots> repository> repositories>
id:该远程仓库的唯一标识;
name:远程仓库的名称;
使该仓库生效:
<activeProfile>centralactiveProfile>
配置镜像:
把对远程仓库的请求转换到对应的镜像地址的请求。每个远程仓库都会有一个id,这样我们就可以创建自己的mirror来关联到该仓库,那么以后需要从远程仓库下载工件的时候Maven就可以从我们定义好的mirror站点来下载,这可以很好的缓解我们远程仓库的压力。在我们定义的mirror中每个远程仓库都只能有一个mirror与它关联,也就是说你不能同时配置多个mirror的mirrorOf指向同一个repositoryId;
1 <mirrors> 2 <mirror> 3 <id>internal-repositoryid> 4 <name>Maven Repository Manager running on repo.mycompany.comname> 5 <url>http://repo.mycompany.com/proxyurl> 6 <mirrorOf>*mirrorOf> 7 mirror> 8 mirrors>
id: 镜像的唯一标识
mirrorOf: 指定镜像规则,什么情况下从镜像仓库拉取,官方文档
*: 匹配所有,所有内容都从镜像拉取external:*: 除了本地缓存的所有从镜像仓库拉取repo,repo1: repo 或者 repo1 ,这里的 repo 指的仓库 ID*,!repo1: 除了 repo1 的所有仓库
name: 名称描述
url: 地址
其他标签说明:
server
如果仓库地址是个私服;需要配置 server
配置分发构建到私服的验证,在setting.xml文件的
<server> <id>server001id> <username>my_loginusername> <password>my_passwordpassword> server>
pluginGroups:
- 元素里包含了一个
pluginGroup列表。默认maven中有org.apache.maven.plugins和org.codehaus.mojo两个pluginGroup。表示当通过plugin的前缀来解析plugin的时候到哪里寻找。pluginGroup元素指定的是plugin的groupId - 如果pom,xml中的plugin没有设置指定groupId,熟悉maven的都知道我们引入以来至少需要groupId和artifactId的。但是下面的插件中没有。这个时候maven就会获取
pluginGroups里pluginGroup列表和配置中artifactId进行一一匹配。匹配到下载。 - jetty 插件的配置 :为了更明确的指向这个groupId是我们需要的插件,唯一的办法就是在settings.xml也做如下设置:
<pluginGroups> <pluginGroup>org.mortbay.jettypluginGroup> pluginGroups>
完整的setting配置:
<?xml version="1.0" encoding="UTF-8"?> <settings> <localRepository>E:/Data/Maven/repositorylocalRepository> <pluginGroups> <pluginGroup>org.mortbay.jettypluginGroup> pluginGroups> <mirrors> <mirror> <id>nexusid> <mirrorOf>*mirrorOf> <url>http://nexus.d.xxx.net/nexus/content/groups/publicurl> mirror> mirrors> <profiles> <profile> <id>developmentid> <repositories> <repository> <id>centralid> <url>http://nexusurl> <releases><enabled>trueenabled>releases> <snapshots><enabled>trueenabled>snapshots> repository> repositories> <pluginRepositories> <pluginRepository> <id>centralid> <url>http://nexusurl> <releases><enabled>trueenabled>releases> <snapshots><enabled>trueenabled>snapshots> pluginRepository> pluginRepositories> profile> profiles> <activeProfiles> <activeProfile>developmentactiveProfile> activeProfiles> <servers> <server> <id>archiva.internalid> <username>yangwenqiangusername> <password>pwdpwdpassword> server> <server> <id>archiva.snapshotsid> <username>yangwenqiangusername> <password>pwdpwdpassword> server> servers> settings>