114

I have created a new maven project in SpringSource Tool Suite. I am getting this error in my new maven project.

Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2): Connect times out

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>

Please note that I am able to build it.Error is showing in pom.xml inside IDE .Any solutions?

Naseer Mohammad
  • 389
  • 4
  • 14
Sajith
  • 2,038
  • 7
  • 27
  • 42

25 Answers25

79

Simplify things by using the following 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>

Under Linux/Unix, place it under ~/.m2/settings.xml. Under Windows place it under c:\documents and settings\youruser\.m2\settings.xml or c:\users\youruser\.m2\settings.xml.

You don't need the <mirrors/>, <profiles/> and <settings/> sections, unless you really know what they're for.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • Thanks for helping.But still getting same error.Note that I am able to build it .error is only in the IDE. – Sajith Mar 11 '13 at 10:15
  • 2
    Okay, then. In your IDE make sure it's pointing to the same `settings.xml` file, as your proxy settings are not getting picked up by your IDE apparently. – carlspring Mar 11 '13 at 10:17
  • I got the same issue when I restarted eclipse in office. It was working fine when I was working from home. So it had to do with proxy settings for corp network. After creating the settings.xml file the way it is described , it worked like charm. – Gopal Bairwa Feb 06 '20 at 22:12
75

This is solved for me when I update maven and check the option "Force update of Snapshots/Releases" in Eclipse. this clears all errors. So right click on project -> Maven -> update project, then check the above option -> Ok. Hope this helps you.

Addition : uncheck "Refresh workspace resources from local filesystem", it's working for me.

vitaliis
  • 4,082
  • 5
  • 18
  • 40
Peter T.
  • 8,757
  • 3
  • 34
  • 32
  • 1
    Thanks it worked for me. I copied eclipse from one machine to another and the maven local cache seems to be the issue behind it for me. When I updated the sanpshot, it worked for me. – Manoj Jan 22 '18 at 06:15
  • 2
    couldn't see this option in my versino of elcipse (photon) – weaveoftheride Sep 19 '18 at 09:18
  • Sometimes the address of the proxy has changed and we do not know. – Willy Makend Dec 11 '18 at 18:28
  • 1
    I have faced the issue: `Failure to transfer xalan:xalan:jar:2.7.1 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact xalan:xalan:jar:2.7.1 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org`. But resolved by `Force Update of Snapshots/Releases`. – Yash Sep 12 '20 at 17:56
29

It seems like your Maven is unable to connect to Maven repository at http://repo1.maven.org/maven2.

If you are using proxy and can access the link with browser the same settings need to be applied to Spring Source Tool Suite (if you are running within suite) or Maven.

For Maven proxy setting create a settings.xml in the .m2 directory with following details

<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>
      <active>true</active>
      <protocol>http</protocol>
      <host>PROXY</host>
      <port>3120</port>
      <nonProxyHosts>maven</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

If you are not using proxy and can access the link with browser, remove any proxy settings described above.

Lii
  • 11,553
  • 8
  • 64
  • 88
Uday Shankar
  • 844
  • 7
  • 20
7

For the first error you can simply clear your local repository cache to force it download from main repository rather than checking the local one.

For second error, if you are behind proxy you should configure it this way Configuring a proxy otherwise you have a network problem now.

Sam R.
  • 16,027
  • 12
  • 69
  • 122
7

To me the solution was just deleted the specific folder which is giving the error from ~/.m2/repository/org/hsqldb/

After deleting the hsqldb folder I have build the project and everything is fine.

smali
  • 4,687
  • 7
  • 38
  • 60
  • This worked for me too. I am using STS. Nothing else worked like Maven-update-force... or settings.xml. In my case the reported error was for maven-surefire-plugin. I deleted this folder which was located at .m2/repository/apache/org/maven/plugins/maven-plugins. After that I cleaned the project and it removed the error in pom.xml – Ankit Oct 07 '15 at 12:05
6

What helped me were the suggestions by @carlspring (create a settings.xml to configure your http proxy):

<?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>

AND then refreshing eclipse project maven as suggested by @Peter T :

"Force update of Snapshots/Releases" in Eclipse. this clears all errors. So right click on project -> Maven -> update project, then check the above option -> Ok. Hope this helps you.

vsm
  • 147
  • 2
  • 9
5

It seems me there was a network issue. On your side, or on Maven side, or anywhere in the middle. Just try again later.

If the error is permanent, check your network settings. If you are behind a proxy, you need the following in you ~/.m2/settings.xml:

<proxies>
    <proxy>
        <id>optional</id>
        <active>true</active>
        <protocol>http</protocol>
        <username>proxyuser</username>
        <password>proxypass</password>
        <host>proxy.host.net</host>
        <port>80</port>
        <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
</proxies>
Étienne Miret
  • 6,448
  • 5
  • 24
  • 36
  • it helped me. but the interesting thing is that only one of Maven plugins (site) needed this proxy setting. and I don't even included them in my pom (just the maven compiler), so not sure why do they even needed to be downloaded.. – Line Jan 20 '21 at 14:42
4

I started using maven on my machine first time in while. Got this error: Could not transfer artifact from/to central (https://repo.maven.apache.org/maven2) No such file or directory Cleaned up ~/.m2/repository directory. Don't experience this problem again

thepolina
  • 1,244
  • 1
  • 14
  • 28
4

Try to use https in repo url: https://repo1.maven.org/maven2

If you use jdk1.7 or above and your network restrict protocols to newer TLS version then enable TLS1.2: -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2

Fabich
  • 2,768
  • 3
  • 30
  • 44
Glaucio
  • 61
  • 2
3

I strongly recommend to use a Maven Repository Manager such as Nexus. It will help you to get stable and reproducible builds with Maven. As the Repository Manager is usually in your LAN, you don't have to configure the proxy settings, but you need to define some other configurations:

http://www.sonatype.com/books/nexus-book/reference/maven-sect-single-group.html

http://maven.apache.org/repository-management.html

Puce
  • 37,247
  • 13
  • 80
  • 152
2

If none of the above works then try and go this question and answer: Maven error "Failure to transfer..."

and delete your .lastUpdated files.

Community
  • 1
  • 1
iaforek
  • 2,860
  • 5
  • 40
  • 56
2
  1. Update Maven Project and check the option "Force update of Snapshots/Releases", it will remove errors.
  2. If not, Maven clean and install the Project.
  3. Still the error isn't removed, repeat step 1.

It worked for me :)

Caffeine Coder
  • 948
  • 14
  • 17
2

This can also happen when using an old version of Java that isn't capable of communicating properly with the HTTPS protocol that is now required. Version 8 and above should work as of the time writing this.

Goddard
  • 2,863
  • 31
  • 37
1

If you are in windows os and dont need any proxy then delete the whole proxy setting

<proxies>
    <proxy>
   ..................
    </proxy>    
  </proxies> 

and replace with

<proxies/> 

and then do a maven clean build

user3123372
  • 704
  • 1
  • 10
  • 26
1

This problem was solved by following steps -

  1. Go to the local m2 repository and find the directory org/apache/maven/plugins/maven-surefire-plugin.
  2. Delete the problematic version.
  3. maven update the project, then download it again.
Saikat
  • 14,222
  • 20
  • 104
  • 125
1

We have the Proxy set on company level.

After disabling proxy in Internet Explorer this issue was solved (looks like it is then disabled on 'system' level), so all other browsers will pick this change too.

Now I can issue MVN commands from CMD prompt and I have no problem while e.g.

"Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.pom"

...that was causing 'Build failure'

Disabling proxy in IE needs to be done on daily basis in our case, because on each system start it gets set

reg
  • 565
  • 2
  • 8
  • 15
1

For me it was File > Settings > ... > BuildTools > Maven > Work Offline[■]

linker
  • 821
  • 1
  • 8
  • 20
1

On IntelliJ go to Preference -> Build, Execution, Deployment -> Build Tools -> Maven. Turn on the checkbox for "Always update snapshots" apply and save changes then do mvn clean install

Meg
  • 248
  • 2
  • 6
1

You can try to set the proxy settings:

File -> Settings -> Appearance -> System Settings -> Http proxy -> Auto Detect

And then provide the proxy URL.

iQuestProgrammer
  • 309
  • 2
  • 5
  • 18
0

If you are not behind any proxy and still getting connection timeout error, please check firewall settings/ antivirus. Sometimes firewall may block the connectivity from any tool (like Eclipse/STS etc..)

Shuvankar Sarkar
  • 409
  • 4
  • 11
0

I changed the java version from 1.7 to 1.8 and it worked

0

The issue is that since maven 3.8.1, they stopped tranferring via HTTP. The simplest solution that worked for me is to simply go to the pom.xml file and under the repository that you are importing, simply replace HTTP with HTTPS. It should work for you.

Hassan Shahzad
  • 455
  • 6
  • 14
0

Right-click on the project. Go to Maven Update project, then check the above option “Force update of Snapshot/Releases“

Purva
  • 383
  • 3
  • 10
0

First, you can do mvn clean and clear the caches of project. Then reload maven package, and force to update maven snapshot can be final attempt.

wei_elsa
  • 41
  • 2
0

I have tested all provided solutions, nothing worked for me.

I'm using a company's network with a proxy, but since I don't have the proxy's credentials, I cannot setup it up in the settings.xml file.

After doing some analysis, I found out that one of my project's dependencies needs to be downloaded from an internal repository.

So I need to add it to the settings.xml file (it's also possible to configure it in the pom.xml)

I have tested 2 solutions that worked for me:

The first one: add the missing repository in the settings.xml file.

Here I ensured that I have all internal repositories that I need to download from.

central-all is a grouped repository that groups central-releases and central-snapshots and the public maven repo (https://repo.maven.apache.org/maven2)

<?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">
    <profiles>
        <profile>
            <id>DEFAULT-PROFILE</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            </properties>
            <repositories>
                <repository>
                    <id>central-all</id>
                    <name>Grouped repository (that contains hosted and proxied repositories)</name>
                    <url>https://company-internal-nexus/nexus/content/groups/central-all</url>
                </repository>
                <repository>
                    <id>central-releases</id>
                    <name>Grouped central-releases repository</name>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <url>https://company-internal-nexus/nexus/content/groups/central-releases/</url>
                </repository>
                <repository>
                    <id>central-snapshots</id>
                    <name>Grouped central-snapshots repository</name>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <url>https://company-internal-nexus/nexus/content/groups/central-snapshots/</url>
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>central-all</id>
                    <name>Grouped repository (that contains hosted and proxied repositories)</name>
                    <url>https://company-internal-nexus/nexus/content/groups/central-all</url>
                </pluginRepository>
                <pluginRepository>
                    <id>central-releases</id>
                    <name>Grouped central-releases repository</name>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <url>https://company-internal-nexus/nexus/content/groups/central-releases/</url>
                </pluginRepository>
                <pluginRepository>
                    <id>central-snapshots</id>
                    <name>Grouped central-snapshots repository</name>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <url>https://company-internal-nexus/nexus/content/groups/central-snapshots/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

The second solution:

Since central-all is a also a proxy to "https://repo.maven.apache.org/maven2", I could have use it in the mirror block defined in settings.xml

    <mirror>
        <id>central-all</id>
        <mirrorOf>central</mirrorOf>
        <url>https://company-internal-nexus/nexus/content/groups/central-all</url>
    </mirror>

Note: by default, the the main Maven Central repository ID is central