1

我正在尝试使用 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
4

2 回答 2

1

下次,请包含您的 build.gradle 文件。

我相信您的问题是由于您尝试应用 plugin:'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
于 2019-01-17T20:53:45.920 回答
0

我遇到了同样的问题,所以我更改为 Gradle 6.5,并将 settings.gradle 文件添加到与 build.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()
    }
}

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

于 2021-03-01T08:31:56.417 回答