春季启动与gradle无法启动

时间:2019-01-17 16:36:00

标签: spring-boot-gradle-plugin

我正在尝试使用Spring工具套件中的gradle build来构建示例hello应用程序,该应用程序面临设计时错误。

我的机器上安装了4.10.2年级版本。

错误消息:

Description Resource    Path    Location    Type
Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.10.2-bin.zip'.
Build file 'C:\TFS\Study\Springboot\GradleExamples\workspace\Gradle_Hello\build.gradle' line: 14
Plugin [id: 'org.springframework.boot', version: '2.1.2.RELEASE'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.2.RELEASE')
  Searched in the following repositories:
    Gradle Central Plugin Repository
Plugin [id: 'org.springframework.boot', version: '2.1.2.RELEASE'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.2.RELEASE')
  Searched in the following repositories:
    Gradle Central Plugin Repository    build.gradle    /Gradle_Hello   line 14 Gradle Error Marker

2 个答案:

答案 0 :(得分:1)

下次,请提供您的build.gradle文件。

我相信您的问题是由您尝试应用插件:'org.springframework.boot'引起的,而没有告诉gradle脚本在哪里可以找到该插件。您的buildscript(build.gradle文件)实际上取决于org.springframework.boot插件,但是由于找不到(甚至不知道它是什么),因此遇到了这个问题。

您可以通过在文件顶部添加以下代码来解决该问题:

buildscript {
   repositories {
      mavenCentral()
   }
   dependencies {
      // You are telling gradle that this script (Not the project) depends on the 
      // following plugin
      classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.2.RELEASE"
   }
}

apply plugin: "org.springframework.boot"

// The rest of your build.gradle file

答案 1 :(得分:0)

我遇到了同样的问题,所以我改用 Gradle 6.5 并在与 build.gradle 相同的目录中添加 settings.gradle 文件,并提供以下信息。

// settings.gradle

pluginManagement {
    plugins {
        id "org.springframework.cloud.contract" version "${verifierVersion}"
    }
    repositories {
        // to pick from local .m2
        mavenLocal()
        // for snapshots
        maven { url "https://repo.spring.io/snapshot" }
        // for milestones
        maven { url "https://repo.spring.io/milestone" }
        // for GA versions
        gradlePluginPortal()
    }
}

此外,请确保您可以连接到您的存储库。在我的情况下,如果是内部 nexus 服务器并且 gradle 无法连接到存储库,因为 JDK 信任库中缺少 SSL 证书。我将 nexus SSL 证书添加到 JDK 信任库中并解决了