Could not transfer artifacts from/to central maven repo when using Spring Framework Cloud
Asked Answered
D

4

6

I am trying to create a maven project using Spring Framework Cloud. I defined pom.xml file as below

<parent>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-parent</artifactId>
        <version>Brixton.RELEASE</version>
    </parent>

    <properties>
        <!-- Stand-alone RESTFul application for testing only -->
        <start-class>io.pivotal.microservices.services.Main</start-class>
    </properties>

    <dependencies>
        <dependency>
            <!-- Setup Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <!-- Setup Spring MVC & REST, use Embedded Tomcat -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <!-- Setup Spring Data common components -->
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
        </dependency>

        <dependency>
            <!-- Testing starter -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <dependency>
            <!-- Setup Spring Data JPA Repository support -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <!-- In-memory database for testing/demos -->
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
        </dependency>

        <dependency>
            <!-- Spring Cloud starter -->
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>

        <dependency>
            <!-- Eureka service registration -->
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
    </dependencies>

When trying to build maven getting error for all dependencies as

Could not transfer artifacts from/to central (https://repo.maven.apache.org/maven2)

Multiple annotations found at this line: - Failure to transfer org.springframework:spring-orm:jar:4.2.6.RELEASE 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 org.springframework:spring-orm:jar:4.2.6.RELEASE from/to central
(https://repo.maven.apache.org/maven2): The operation was cancelled. org.eclipse.aether.transfer.ArtifactTransferException: Failure to transfer org.springframework:spring-orm:jar: 4.2.6.RELEASE 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 org.springframework:spring-orm:jar:4.2.6.RELEASE from/to central (https://repo.maven.apache.org/maven2): The operation was cancelled. at
org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:238) at
org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:206) at
org.eclipse.aether.internal.impl.DefaultArtifactResolver.gatherDownloads(DefaultArtifactResolver.java:585) at
org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:503) at
org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421) at
org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246) at
org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:367) at

When I go to the location, I can clearly see the Jar files are present in that location. Is there something else I need to add to my pom.xml?

Duplessismornay answered 7/12, 2017 at 7:50 Comment(8)
Most likely you're behind a corporate proxy and maven hasn't been configured for it.Flynn
There is no such proxy setting. Also, If I override the default version with some other version, it successfully downloadsDuplessismornay
Default version of what?Flynn
Have you run Maven on command line or from within Eclipse? If in eclipse please try from plain command line...Apart from that which version of Maven are you using? If this does not help. Delete the directory $HOME/.m2/repository/org/springframework and retry...Donato
@Flynn - I am using Brixton.RELEASE which by default looks for org.springframework.boot:spring-boot-starter-web:jar:1.3.5.RELEASE. But if I override version as <version>1.3.6.RELEASE<\version> it downloads successfully. Same for other dependency as wellDuplessismornay
@Donato I am using STS. I tried deleting the .m2 repository, but still facing the issueDuplessismornay
It's strange, if it's working for one version and not working for a specific version. I tried your pom and it's working for me, that means there's nothing wrong with POM itself. Try running with -X or --debug may be that will give more clues.Flynn
Actually, I switched from STS to eclipse and surprisingly same pom.xml is working fine. It's a mystery how this could be IDE dependent. And that too when STS is built over Eclipse itself. I am clueless.Duplessismornay
D
2

I tried the same pom.xml inEclipse IDE and surprisingly it worked there as it is.

To make it work on STS, I added following properties

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <start-class>io.pivotal.microservices.services.Main</start-class>
        <spring-cloud.version>Brixton.RELEASE</spring-cloud.version>
    </properties>

Refer Unable to download/import package org.springframework.cloud.config.server.EnableConfigServer

This worked for me, though I am still curious about the difference.

Duplessismornay answered 8/12, 2017 at 12:59 Comment(0)
P
6

Try force refreshing your dependencies. Specifying -U does that

mvn clean install -U

Edit: You can purge your local release dependencies and to the normal mvn clean install afterwards:

mvn dependency:purge-local-repository

There is not way to force the release dependencies to be pulled, the -U only works with snapshot dependencies

Physician answered 7/12, 2017 at 7:54 Comment(1)
Thanks, but this was the first thing I tried doing. Unfortunately, it did not work.Duplessismornay
D
2

I tried the same pom.xml inEclipse IDE and surprisingly it worked there as it is.

To make it work on STS, I added following properties

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <start-class>io.pivotal.microservices.services.Main</start-class>
        <spring-cloud.version>Brixton.RELEASE</spring-cloud.version>
    </properties>

Refer Unable to download/import package org.springframework.cloud.config.server.EnableConfigServer

This worked for me, though I am still curious about the difference.

Duplessismornay answered 8/12, 2017 at 12:59 Comment(0)
R
1

I had yet a different problem - strangely enough some of the directories in .m2 path were owned by root, not by a local user. Changing ownership (chown) fixed it for me. Maybe someone will find it helpful as it wasn't an obvious thing to check/consider.

Rutheruthenia answered 2/4 at 12:46 Comment(0)
U
0

I had the same error on my project and this is what worked for me.

First of all, go to your pom.xml and find your spring-parent version. Then go to https://repo.maven.apache.org/maven2/springframework/spring-parent and check if your same springframework version exists, if not change your springframework version to an existing one.

Ukulele answered 26/4, 2022 at 13:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.