Maven dependency and repository (part b)

Repository介绍
 
Artifact Repositories
Repository 就是用来存储 artifacts and dependencies (实质也就是 artifact )的地方。
2 种类型的 repositories: local and remote local repository 里存储了因有使用需要而从 remote repository 下载的 artifacts cache ,还存储了你在本地 build 的,但还没有发布到 remote repository artifacts
Remote repositories 能够被 accessed by 各种协议(如 file:// and http:// )。 Remote repositories 可以是真正供所有人都可以进入的 repositorie (例如: Maven's central repository  repo1.maven.org 就是典型例子 ) ,也可以是一个 build 在你公司内部 http server internal repositories ,它只在你们的开发团队里共享。
The local and remote repositories 的结构是相同的,但作为 maven 的使用者,我们不需要去深入了解它的结构。
 
Why not Store JARs in CVS?
Maven 强烈建议不要在你的 project 里包含任何要引用的 JARs ,即 project 不要存储这些 jars ,而应该定义对这些 jars dependency 。例如,很多的 project 都会使用到一些常用的 jar (如 junit, XML parsers standard utilities ), 你不要把他们的 jar 都放入你的 project 里,而应该使用它们的 dependencies
这些 dependencies 存储在 local repositoty 里可以供成千上万个 project 使用 ,其好处有:
·         It uses less storage 每个 JAR 只存储在 repository 一个地方,所有的 project 如果要使用它就定义它的 dependency 即可,节约了空间,同时也使你的 project cleaner
·         It makes checking out a project quicker - initial checkout, and to a small degree updating, a project will be faster if there are no large binary files in CVS. While they may need to be downloaded again afterwards anyway, this only happens once and may not be necessary for some common JARs already in place.
·         No need for versioning – CVS and other source control systems are designed for versioning files, but external dependencies typically don't change, or if they do their filename changes anyway to indicate the new version. Storing these in CVS doesn't have any added benefit over keeping them in a local artifact cache.
 
Using Repositories
通常, 你不需要对 local repository 做任何事,除非你想重新 download 所有的 artifact 而清空 local repository
而对于 remote repositories, 它们是用来 download and upload artifact ( 当然,你必须有权限才可以操作 ).
Downloading from a Remote Repository
当一个 project 定义的 dependency local repository 里找不到,或者 remote repository 包含了新版本时,就会激活 Download the dependency from remote repository 的操作。
缺省情况下,会从 maven central repository (http://repo1.maven.org/maven2 ) 下载。如果你还希望能够从其他的 remote repository 下载(比如要下载只供你们 team 使用的 artifact ),你需要在 POM.XML 里做下列设置:
<project>
 ...
 <repositories>
    <repository>
      <id>my-internal-site</id>
      <url>http://myserver/repo</url>
    </repository>
 </repositories>
 ...
</project>
上述设置也可以在 settings.xml
Using Mirrors for the Central Repository
就象 web server 一样, central repository 有时也会 down 机。如果这种情况发生了,你可以在 settings.xml 里设置 <mirrors> element 详见 Using Mirrors for Repositories .
 
Build Offline
如果你在使用 maven build project 时你的电脑无法连上网,那么你可以在 mvn 命令里添加 -o 参数
 mvn -o package
但要注意:许多 plugins 在设置为 offline 的情况下不会执行任何需要连接上网的操作,就会导致失败。
 
Internal Repositories
 
对于团队合作开发的project,建一个internal repository,使得团队成员能够共享、下载、上传最新的artifact,是非常必要的。 internal repository 并没有什么特别,它实际上就是一个 remote repository
团队成员可以使用 HTTP or the file system (using a file:// URL) 的方式从 internal repository 下载 artifact ,也可以使用 SCP, FTP, or a file copy 的方式上传 artifact internal repository
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值