【问题标题】:Gradle Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE (repo1.maven.org: Nome o servizio sconosciuto)Gradle 无法解析 org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE (repo1.maven.org: Nome o servizio sconosciuto)
【发布时间】:2017-06-18 04:49:58
【问题描述】:

我在 Jenkins 上运行 gradle 构建时遇到问题: Gradle 版本是 https://services.gradle.org/distributions/gradle-2.14.1-bin.zip

FAILURE:构建失败并出现异常。 * 什么地方出了错: 配置根项目“myApp”时出现问题。 > 无法解析配置“:classpath”的所有依赖项。 > 无法解析 org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE。 要求: :myApp:未指定 > 无法解析 org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE。 > 无法获取资源'https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.4.2.RELEASE/spring-boot-gradle-plugin-1.4.2。释放.pom'。 > 无法 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 * 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。

这是我的 build.gradle 文件:

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'

}

【问题讨论】:

    标签: java spring jenkins gradle


    【解决方案1】:

    正如错误告诉您Nome o servizio sconosciutorepo1.maven.org 无法通过 DNS 解析。所以你有一些网络问题,或者你需要使用你没有为 Gradle 配置的代理服务器。向您的 IT 支持人员询问您无法解析主机名的原因。

    【讨论】:

      【解决方案2】:

      这可能是网络问题。如果没有,请尝试以下步骤,因为它解决了我的问题。

      由于我也面临同样的问题,我尝试通过更改依赖关系来解决它。

      这个值给我一个错误。

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

      这是有效的

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

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

      【讨论】:

        【解决方案3】:

        当我第一次尝试在 IntelliJ 上使用 gradle 3.5 使用我的笔记本电脑运行 gradle 时,我遇到了 spring-boot-starter 依赖项无法解决的问题,无需代理。

        问题不见了:

        apply plugin: 'org.springframework.boot'
        

        来自 build.gradle 文件。一旦包含它,它就会立即下载所有依赖项。

        【讨论】:

        • 我阅读了整个错误,但回答了其中一种可能的情况。如果依赖项没有下载,可能有很多原因。我无法对上述答案发表评论,所以我单独回答。总之谢谢
        【解决方案4】:

        我也遇到过这个问题,但原因与当前接受的答案不同。

        在我的例子中,包含依赖项的服务器没有正确传递凭据。

        凭据是在主机容器的环境变量中设置的,但在进行调用的子容器中不存在,因此连接在主机容器上工作正常,但因子问题中列出的Could not resolve... 错误而失败容器。

        通过使用-D optionsMAVEN_USERNAMEMAVEN_PASSWORD 传递给gradle 解决了这个问题:

        $ gradle -DMAVEN_USERNAME=foo -DMAVEN_PASSWORD=bar
        

        【讨论】:

        • 您必须始终查看最后的错误消息(从上到下)。在这种情况下是`repo1.maven.org: Nome o servizio sconosciuto`(或英文Name or service not known error?)导致Could not resolve dependecy错误。
        【解决方案5】:

        您的构建文件没有 spring boot 插件。

        应用插件:

        'org.springframework.boot'
        

        没有这个,Spring boot 的依赖管理系统就会被破坏

        【讨论】:

        • 你确定吗?因为我的 build.gradle 包含 org.springframework.boot:spring-boot-gradle-plugin 并且修复了我的 Internet 连接(dns 解析)问题已解决。
        【解决方案6】:

        这可能是由于网络问题。如果你在代理后面,那么在 eclipse 中去 步骤 1) 窗口 -> 首选项 -> 网络连接, 此处提供代理详细信息(代理、端口号)和 步骤 2) 选中 AUTH 框,然后输入 userId 和 Password。 Step 3) 然后点击gradle refresh

        在我的情况下,这是我选中 Auth 框并输入用户名和密码时的问题。

        【讨论】:

          【解决方案7】:

          每当我第一次尝试在不同的系统中进行干净的构建或您的系统中安装了多个 java 时,这都是我的例行公事。

          您可能会遇到存储库找不到问题或信任来源问题。 因此,对于两者来说,以下解决方案都应该有效。

          通过投资,我发现这是由于您的 Java 无法与给定的存储库正常通信。

          按照以下步骤解决此问题。

          • 将 maven 存储库公共证书添加到本地 java。

          • 获取任何 URL 的锁定图标的公共证书并转到证书(有效)链接

          • 将文件复制到本地文件夹,并使用正确的名称和扩展名作为 .cer

          • 下载此文件后,将其添加到您的 Java 可信证书中。

             keytool -import -trustcacerts -keystore {java_path}/jre/lib/security/cacerts -storepass changeit -noprompt -alias my_alias -file {certificate_path}\certificates.cer
            
          • 成功将证书添加到您的 java 后,转到您的存储库

          • 运行以下命令来清理和构建您的 Gradle 项目

            gradlew build -x test --refresh-dependencies --stacktrace -Djavax.net.ssl.trustStore={your_java_path}\jre\lib\security/cacerts -Djavax.net.ssl.trustStorePassword=changeit  
            
          • 这里,在上面的命令中,我们明确地提供了 java 证书路径及其密码。

          在此过程之后,您的干净构建应该可以工作。希望这个答案对其他人有所帮助。

          【讨论】:

            猜你喜欢
            • 2021-05-18
            • 1970-01-01
            • 1970-01-01
            • 2022-10-31
            • 2021-01-24
            • 1970-01-01
            • 2021-10-09
            • 2022-07-27
            相关资源
            最近更新 更多