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

2022-08-31 09:55:07

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

未能从缓存在本地存储库中的 http://repo1.maven.org/maven2 传输 org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1,在中心更新间隔过或强制更新之前,不会重新尝试解析。原始错误:无法将 artifact 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 中显示错误。任何解决方案?


答案 1

通过使用以下内容简化操作: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.xmlc:\documents and settings\youruser\.m2\settings.xmlc:\users\youruser\.m2\settings.xml

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


答案 2

当我更新maven并选中Eclipse中的“强制更新快照/版本”选项时,这个问题就解决了。这将清除所有错误。因此,右键单击项目->Maven->更新项目然后选中上面的选项->确定。希望这对您有所帮助。

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


推荐