现在的位置: 首页 > 综合 > 正文

Maven 包依赖

2018年03月23日 ⁄ 综合 ⁄ 共 1489字 ⁄ 字号 评论关闭

 Maven的生命周期的概念比Ant更加的便捷和优秀,而Maven的包依赖存在着颇多争议,我们在内网中不得不手动的搭建自己的私服,每个成员在第一次的时候都必须从中心仓库来下载依赖的包,Maven之所以在开源项目,尤其是在国外优秀的开源项目中颇受青睐,其实更多的是项目管理的理念的先进和规范,依赖包的统一和规范对项目的重要性不言而喻,却受不到我们的重视;

 

 

每一次在执行maven package的时候,都是执行以下几个Plugin Goals:

 

 

 

会从中央中心下载依赖包,如下:

 

Downloading: http://repo1.maven.org/maven2/junit/junit/3.8.2/junit-3.8.1.jar

 

这个时候会从中央仓库下载:

 

 

 这里的Pom是用于依赖传递的,这样我们就可以不在项目中引入Junit自身依赖的包;如果无法从中央仓库下载依赖包的话:则会发生错误:

 

[WARNING] Unable to get resource 'junit:junit:jar:3.8.2' from repository central
 (
http://repo1.maven.org/maven2): Error transferring file: repo1.maven.org
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

 

 

 

有两种解决方式:

 

1) junit:junit:jar:3.8.2

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=junit -DartifactId=junit -Dversion=3.8.
2 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:

      mvn deploy:deploy-file -DgroupId=junit -DartifactId=junit -Dversion=3.8.2
-Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
        1) org.corey.weather:CoreyWeather:jar:1.0
        2) junit:junit:jar:3.8.2

----------

 

第一个是手动的安装这些包,将他们按照~/repos/groupId/artficastId/version/artficast.version.jar

第二则是制定-Dfile=/path/to/file

【上篇】
【下篇】

抱歉!评论已关闭.