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

发布于 2021-01-31 15:35:24

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

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

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>

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">
  <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中显示错误。任何解决方案?

关注者
0
被浏览
101
1 个回答
  • 面试哥
    面试哥 2021-01-31
    为面试而生,有面试问题,就找面试哥。

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

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



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看