无法将工件 org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 从/传输到中央 (http://repo1.maven.org/maven2)

新手上路,请多包涵

我在 SpringSource Tool Suite 中创建了一个新的 maven 项目。我在我的新 Maven 项目中遇到了这个错误。

http://repo1.maven.org/maven2 传输 org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 失败被缓存在本地仓库,直到更新间隔才会重新尝试解析中央已过或强制更新。原始错误:无法从/到中央传输工件 org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 ( http://repo1.maven.org/maven2 ):连接超时

pom.xml:

 <project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test.app</groupId>
  <artifactId>TestApp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>TestApp</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

设置.xml

 <?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <pluginGroups>
  </pluginGroups>
 <proxies>
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>user</username>
      <password>pass</password>
      <host>ip</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
  </proxies>
  <servers>
  </servers>
    <mirrors>
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://repo1.maven.org/maven2/</url>
    </mirror>
  </mirrors>
<profiles>
 </profiles>
</settings>

请注意,我能够构建它。错误显示在 IDE 内的 pom.xml 中。任何解决方案?

原文由 Sajith 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 786
2 个回答

通过使用以下 settings.xml 来简化事情:

 <?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              http://maven.apache.org/xsd/settings-1.0.0.xsd">

 <proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>user</username>  <!-- Put your username here -->
      <password>pass</password>  <!-- Put your password here -->
      <host>123.45.6.78</host>   <!-- Put the IP address of your proxy server here -->
      <port>80</port>            <!-- Put your proxy server's port number here -->
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts> <!-- Do not use this setting unless you know what you're doing. -->
    </proxy>
  </proxies>
</settings>

在 Linux/Unix 下,将其放在 ~/.m2/settings.xml 下。在 Windows 下,将其放在 c:\documents and settings\youruser\.m2\settings.xmlc:\users\youruser\.m2\settings.xml 下。

您不需要 <mirrors/><profiles/><settings/> 部分,除非您真的知道它们的用途。

原文由 carlspring 发布,翻译遵循 CC BY-SA 3.0 许可协议

当我更新 Maven 并在 Eclipse 中选中“ 强制更新快照/版本”选项时,这对我来说就解决了。这将清除所有错误。所以 右击项目-> Maven -> update project然后勾选上面的选项-> Ok 。希望这对你有帮助。

添加:取消选中“从本地文件系统刷新工作区资源”,它对我有用。

原文由 Peter T. 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题