gpt4 book ai didi

java - gradle 无法应用插件 [id 'org.springframework.boot' ]

转载 作者:行者123 更新时间:2023-12-01 13:37:41 25 4
gpt4 key购买 nike

我正在尝试运行 spring-boot 项目。我对gradle有一些问题。

毕业 构建工作正常,但我无法运行 毕业

无法运行命令:./gradlew build &&java -jar build/libs/gs-spring-boot-docker-0.1.0.jar
这是错误:

Failed to apply plugin [id 'org.springframework.boot']
Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.9

我的毕业版本 6.0

我的毕业文件
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE")
classpath('com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:1.8.0')
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.cloud.tools.jib'


bootJar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}

repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.postgresql:postgresql')
testCompile("org.springframework.boot:spring-boot-starter-test")
}

gradle build 工作正常,没有错误。

最佳答案

Gradle 包装器的全部意义在于在项目中使用固定版本的 Gradle。这可确保您不会意外使用与项目支持的版本不兼容的版本。另一个好处是,如果您还没有正确的版本,它会自动下载它。

当您键入 gradle (没有'w'),您正在调用您放在路径上的手动下载的发行版。这完全跳过了包装部分。在您的情况下,您显然已经下载了版本 6 并更新了项目以使用该版本。

但是,您还没有更新包装脚本,而这正是您应该做的。如果您查看 gradle/wrapper/gradle-wrapper.properties ,您应该看到它设置为 4.9,它不再与您的项目兼容。

要更新它,您需要运行以下命令两次:
gradlew wrapper --gradle-version 6.1.1 --distribution-type all (假设您需要 6.1.1 版本,这是撰写本文时的最新版本。)

第一次运行它基本上只是更改gradle-wrapper.properties中的版本(例如到 6.1.1)。如果由于包装器与项目相比太旧而导致失败,只需使用文本编辑器手动更改文件即可。

第二次运行时,Gradle 将使用该新版本(例如 6.1.1)启动,如果需要,更新包装脚本本身。

此外,如果您想在开发过程中启动 Spring Boot 应用程序,只需运行 gradlew bootRun .无需手动构建 jar 和调用 java。

而且,而不是 compile , 使用 implementation在您的依赖项中。前者已弃用(包括 testCompile )。

关于java - gradle 无法应用插件 [id 'org.springframework.boot' ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60019141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com