41

I have a problem running a gradle build on Jenkins: Gradle version is https://services.gradle.org/distributions/gradle-2.14.1-bin.zip

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'myApp'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE.
     Required by:
         :myApp:unspecified
      > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE.
         > Could not get resource 'https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.4.2.RELEASE/spring-boot-gradle-plugin-1.4.2.RELEASE.pom'.
            > Could not HEAD 'https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.4.2.RELEASE/spring-boot-gradle-plugin-1.4.2.RELEASE.pom'.
               > repo1.maven.org: Nome o servizio sconosciuto

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

This is my build.gradle file:

buildscript {
    ext {
        springBootVersion = '1.4.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'


war {
    baseName = 'myApp'
    version = '1.0.5'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    compile('org.springframework.boot:spring-boot-starter-security')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('com.fasterxml.jackson.core:jackson-core:2.7.3')
    compile("org.springframework:spring-jdbc")
    compile('com.fasterxml.jackson.core:jackson-databind:2.7.3')
    compile('com.fasterxml.jackson.core:jackson-annotations:2.7.3')
    compile files('src/main/resources/static/lib/ojdbc7.jar')
    // https://mvnrepository.com/artifact/org.json/json
    compile group: 'org.json', name: 'json', version: '20080701'

}
1
  • Please also select correct gradle java version
    – Vijay
    Apr 20 at 9:14

10 Answers 10

12

As the error tells you Nome o servizio sconosciuto, repo1.maven.org cannot be resolved via DNS. So you have some networking problem or you need to use a proxy server which you did not configure for Gradle. Ask your IT support as to why you cannot resolve the hostname.

7

I was getting spring-boot-starter dependency cant be resolved issue when i tried to run gradle first time on IntelliJ using gradle 3.5 using my laptop no proxy required.

The issue was missing:

apply plugin: 'org.springframework.boot'

from the build.gradle file. Once included it downloaded all the dependencies in a flash.

1
  • I read the entire error, but answered for one of the possible scenarios. If dependency is not downloading there can be lot of reasons. I couldn't comment on the above answer so I answered separately . Anyways thanks Nov 1, 2017 at 7:40
6

This is might be a network issue. If not then please try below steps as it solved my issue.

As I was also facing the same problem, I tried to solve it by changing the dependencies.

This value gives me an error.

compile("org.springframework.boot:spring-boot-starter-ws") 

This is what works

compile group: 'org.springframework.boot', name: 'spring-boot-starter-ws', version: '1.4.7.RELEASE'

Ref:https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-ws/1.1.8.RELEASE

2

I experienced this issue as well but for a different reason than the currently accepted answer.

In my case, it was that the server housing the dependencies was not being passed the credentials properly.

The credentials were set in environment variables on a host container but not present in a child container making the call, so the connection worked fine on the host container, but failed with the Could not resolve... errors listed in the question on the child container.

This was resolved by passing MAVEN_USERNAME and MAVEN_PASSWORD to gradle using -D options:

$ gradle -DMAVEN_USERNAME=foo -DMAVEN_PASSWORD=bar
1
  • You have always to watch last error messages (from up to bottom). In this case is ` repo1.maven.org: Nome o servizio sconosciuto` (or in english Name or service not known error?) that causes a Could not resolve dependecy error.
    – sgargel
    Oct 16, 2019 at 7:40
1

This might occur due to network problem. If you are behind the proxy, then in eclipse go to Step 1) window -> Preferences -> Network Connections, here give the proxy details (proxy,port Number) and Step 2) check the AUTH box then enter userId and Password. Step 3) Then click the gradle refresh

In my case this was the issue when I checked the Auth box and entered user and password it worked immediately.

0

This is routine with me whenever I tried to do a clean build first time into a different system or system have multiple java installed.

You may face repository could not found issue or trust origin issue. So for both the issue following solution should work.

By review this issue, I figured it out that it is due to Java could not communicate with the given repository server properly.

Follow the below steps to resolve this issue.

  • Add library server's public certificates to local java for which issue is faced.

  • To get a public certificate of any URL, click on lock icon in browser address bar and go to the certificate (valid) link.

public certificate

  • Copy downloaded file to your local folder with proper name and extension as .cer

  • After download, Add this file to Java trusted certificate keytool. to import certificate, check below command.

    keytool -import -trustcacerts -keystore {java_path}/jre/lib/security/cacerts -storepass changeit -noprompt -alias my_alias -file {certificate_path}\certificates.cer
    
  • After successfully adding a certificate to java, go to repository.

  • Run the following command to clean and build Gradle project.

    gradlew build -x test --refresh-dependencies --stacktrace -Djavax.net.ssl.trustStore={your_java_path}\jre\lib\security/cacerts -Djavax.net.ssl.trustStorePassword=changeit  
    
  • Here, in the above command, we are explicitly providing the java certificate path and its password. above clean build should work properly now.

Hope this answer will help other.

3
  • 1
    You are a savior. I tried multiple ways & tired. Finally your answer helped me in resolving the issue. Oct 4, 2022 at 11:24
  • Can we get a more detailed explanation? "Add maven repositories public certificates to your local java." - What does that even mean? What's my "local java"? And in general, how do I add "maven repositories public certificates" to it? Like call me stupid, but you've explained nothing.
    – Tigerrrrr
    Feb 17 at 17:13
  • To understand this answer, you must have basic knowledge of java and certificate issue. you can download any public certificate from tjhe domain as mentioned in following points. to add any public certificate to java, you have to use keytool. may be my formatting cause understanding issue Feb 18 at 18:25
-1

Your build file does not have the spring boot plugin.

apply plugin:

'org.springframework.boot'

Without this the dependency management system is broken for Spring boot

1
  • Are your sure? Because my build.gradle contains org.springframework.boot:spring-boot-gradle-plugin and the problem was solved fixing my internet connection (dns resolution).
    – sgargel
    May 18, 2017 at 7:03
-1

Just had the same problem with Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.0 and the old eclipse 2021-09. For me upgrading to version 2022-09 fixed the issue.

(also tried some messing around with the dns settings of Windows and CloudFlare WARP first, but that didn't do anything)

-1

adding apply plugin: 'org.springframework.boot' in build.gradle

fixed my problem with gradle build.

-1

I had the same problem. I was using gradle-7.5.1, I switched to gradle-8.1.1, and everything working fine, without any change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.