管理工具---Maven系列(一)编译问题Could not resolve dependencies for project

版权声明:如有转载-请加微信457556886告知下就可以 知识都是分享的 https://blog.csdn.net/wolf_love666/article/details/72625465

***Maven install编译报错:Could not resolve dependencies for project
Could not resolve dependencies for project
org.springframework.samples.service.service:
com.lvwang.osf:war:0.0.1-SNAPSHOT:
The following artifacts could not be resolved:
ch.qos.logback:logback-classic:jar:1.0.13,
ch.qos.logback:logback-core:jar:1.0.13,
commons-logging:commons-logging:jar:1.2:
Could not transfer artifact ch.qos.logback:
logback-classic:jar:1.0.13 from/to nexus
Connect to failed:
Connection timed out: connect -> [Help 1]*
分析:
DependencyResolutionException
1、This error generally occurs when Maven could not download dependencies.
1、这个错误通常发生在当maven不能下载依赖的时候。
Possible causes for this error are:
造成这个错误的原因有如下几种:

1、The POM misses the declaration of the <repository> which hosts the artifact.
1、这个pom文件丢失了 <repository> 的这个artifact相应的坐标。正确格式如下:
<dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>

2、The repository you have configured requires authentication and Maven failed to provide the correct credentials to the server. In this case, make sure your ${user.home}/.m2/settings.xml contains a declaration whose matches the of the remote repository to use. See the Maven Settings Reference for more details.
**2、你已经配置了请求权限给该库和maven不能提供正确的凭证(权限)给这个服务器–意思就是你配置的请求权限有问题。
举个例子:**

确保你的${user.home}/.m2/settings.xml该库的路径包含了 <server> 服务器的申明,并且该服务器的 <id>匹配你远程仓库的 <id>。如何引用maven的设置看如下:

Servers
The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. However, certain settings such as username and password should not be distributed along with thepom.xml. This type of information should exist on the build server in the settings.xml.
这些库是为了下载和部署被这pom文件中定义这些库和构建发布元素的。
然而,某个配置设置例如用户名username和password 本不应该管理 和这个pom.xml有联系的。这个类信息应该存在建立的服务器的 setttins.xml配置文件中。

1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  2.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
  4.                       https://maven.apache.org/xsd/settings-1.0.0.xsd">
  5.   ...
  6.   <servers>
  7.     <server>
  8.       <id>server001</id>
  9.       <username>my_login</username>
  10.       <password>my_password</password>
  11.       <privateKey>${user.home}/.ssh/id_dsa</privateKey>
  12.       <passphrase>some_passphrase</passphrase>
  13.       <filePermissions>664</filePermissions>
  14.       <directoryPermissions>775</directoryPermissions>
  15.       <configuration></configuration>
  16.     </server>
  17.   </servers>
  18.   ...
  19. </settings>
id: This is the ID of the server (not of the user to login as) that matches the id element of the repository/mirror that Maven tries to connect to.
  ● id:这是这个服务器匹配这个maven试图连接的库或者镜像的这个id元素,不是用户登陆的id
  ● username, password: These elements appear as a pair denoting the login and password required to authenticate to this server.
  ● username, password:这些元素指向了一对这个服务器所要权限的登陆用户名和密码
  ● privateKey, passphrase: Like the previous two elements, this pair specifies a path to a private key (default is ${user.home}/.ssh/id_dsa) and a passphrase, if required. The passphrase and password elements may be externalized in the future, but for now they must be set plain-text in the settings.xml file.
  ● privateKey, passphrase:像这前面的两个元素,这对指向了一个私钥路径(默认是${user.home}/.ssh/id_dsa)和一个密码,如果必须,这个通行证密码和上面的密码元素也许未来会被改动扩展,但是对于现在,他们必须被设置明文在settings.xml这个文件中
  ● filePermissions, directoryPermissions: When a repository file or directory is created on deployment, these are the permissions to use. The legal values of each is a three digit number corrosponding to *nix file permissions, ie. 664, or 775.
  ● filePermissions, directoryPermissions: 当一个库文件或者目录在发布中被创建,这些是使用的权限。这每一个规定的值是一个三 位数字 和文件权限一致  例如664 或者775.
Note: If you use a private key to login to the server, make sure you omit the <password> element. Otherwise, the key will be ignored.
注意:如果你使用了一个私钥登陆这个服务器,确保你删除了这个<password>元素,否则这个密钥就会被忽略。

3、The remote repository in question uses SSL and the JVM running Maven does not trust the certificate of the server.
3、这个远程仓库在请求时候使用SSL协议和这个虚拟机运行的maven不信任这个服务器的认证。
4、There is a general network problem that prevents Maven from accessing any remote repository, e.g. a missing proxy configuration.
4、这是一个普遍的网络问题阻止了maven从任何远程仓库下载权限,例如丢失了代理配置。
5、You have configured Maven to perform strict checksum validation and the files to download got corrupted.
5、你已经配置了maven执行校验和这些文件下载被中端。
6、Maven failed to save the files to your local repository, see LocalRepositoryNotAccessibleException for more details.
In case of a general network-related problem, you could also consult the following articles:
Configuring a Proxy
Security and Deployment Settings
Guide to Remote Repository Access through Authenticated HTTPS
**6、maven失败保存这些文件到你本地仓库,看本地仓库没有权限异常获取更多信息。例如一个通常网络连接问题,你可以看看如下文章可能有帮助。
配置一个代理**

  1. <settings>
  2.   .
  3.   .
  4.   <proxies>
  5.    <proxy>
  6.       <id>example-proxy</id>
  7.       <active>true</active>
  8.       <protocol>http</protocol>
  9.       <host>proxy.example.com</host>
  10.       <port>8080</port>
  11.       <username>proxyuser</username>
  12.       <password>somepassword</password>
  13.       <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
  14.     </proxy>
  15.   </proxies>
  16.   .
  17.   .
  18. </settings>

安全和部署settings文件

  1. <settings>
  2.   .
  3.   .
  4.   <servers>
  5.     <server>
  6.       <id>repo1</id>
  7.       <username>repouser</username>
  8.       <!-- other optional elements:
  9.         <password>my_login_password</password>
  10.         <privateKey>/path/to/identity</privateKey> (default is ~/.ssh/id_dsa)
  11.         <passphrase>my_key_passphrase</passphrase>
  12.       -->
  13.     </server>
  14.   </servers>
  15.   .
  16.   .
  17. </settings>

通过HTTPS权限指向远程仓库。
http://maven.apache.org/guides/mini/guide-repository-ssl.html

展开阅读全文

没有更多推荐了,返回首页