maven默认有一个中央服务器,定义在${M2_HOME}/lib/maven-2.0.10-uber.jar里
maven的全局配制文件为 ${M2_HOME}/conf/settings.xml
maven的用户级配制文件在 ${user.home}/.m2/settings.xml
这里可以
1. 修改 localRepository的路径,默认在 ${user.home}/.m2/repository下
<localRepository>/path/to/local/repo</localRepository> <offline>false</offline>
2. server,在分发验证用户密码
<server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server>
3. mirror ,设置repository的镜像,mirrorOf是指定哪个repository,*指所有repository
<mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror>
4. profile 可以预先定义 repository和 pluginRepository,并可以通过activeProfiles指定哪个profile生效,也可以通过条件触发
<profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>jdk14</id> <name>Repository for JDK 1.4 builds</name> <url>http://www.myhost.com/maven/jdk14</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> <activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile> </activeProfiles>
5. repository定义时可以指定是否需要从snapshot和 release取得资源
6. 打包,maven会识别项目version是否含有 -SNAPSHOT 后缀,有的话则在deploy时自动将该包upload到SNAPSHOT repository中,若没有则upload 到 release repository中。
7. 项目构建时maven会先从local repository中取jar,如果没有则去remote中取得并缓存到local中,若该包version后缀为-SNAPSHOT,那么每次构建时都会自动去SNAPSHOT repository中抓取,release version有缓存就用缓存
8. install会将构件安装到 本地库中,deploy将构件安装到远程库中
mvn install:install-file -Dfile=path-to-your-artifact-jar -DgroupId=your.groupId -DartifactId=your-artifactId -Dversion=your-version -Dpackaging=jar -DgeneratePom=truemvn deploy:deploy-file -DrepositoryId=your-repository-id -Durl=dav:your-repository-url -DgroupId=your.groupId -DartifactId=your-artifactId -Dversion=your-version -Dpackaging=jar -Dfile=jar-name