我遵循这里最新的spring.framework.boot
插件的说明。
我的build.gradle
plugins {
id 'java-library'
id 'eclipse'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.springframework.boot' version '2.6.2'
id 'org.springframework.boot.experimental.thin-launcher' version '1.0.23.RELEASE'
}
但是gradle任务有一个错误
> Could not resolve all dependencies for configuration ':detachedConfiguration1'.
> Could not find org.springframework.boot:spring-boot-dependencies:2.6.2.
我忽略了添加错误描述的最后一行,这对回答错误非常重要。
Searched in the following locations:
- https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-dependencies/2.6.2/spring-boot-dependencies-2.6.2.pom
- https://repo.spring.io/milestone/org/springframework/boot/spring-boot-dependencies/2.6.2/spring-boot-dependencies-2.6.2.pom
发布于 2022-01-07 17:25:44
感谢上面的@granadaCoder,在将Gradle重新安装到最新版本的7.3.3
之后,实际的问题是第二个存储库设置已经进入了我的build.gradle
repositories {
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
这正是错误说找不到依赖项的地方。我把这个换成了
repositories {
mavenCentral()
}
事情就开始起作用了。
发布于 2022-01-07 16:36:09
下面是一个完整的文件作为示例:(这是根build.gradle) (如果您编写了一个monolith,您将只有一个根build.gradle,如果您编写了多个"gradle模块“,您将有一个根和子项目build.gradle文件)(如果您不知道我在说什么--参见下面的docs.gradle.org链接)
(您可以删除依赖项,但我更喜欢完全工作)
plugins {
id 'org.springframework.boot' version '2.6.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-batch'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'com.h2database:h2'
implementation 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.batch:spring-batch-test'
testImplementation 'org.springframework.integration:spring-integration-test'
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
allprojects {
/* custom task to show dependencies. run "gradle printAllDependencies" from commandline. see https://stackoverflow.com/questions/44266687/how-to-print-out-all-dependencies-in-a-gradle-multi-project-build/54436979#54436979 */
task printAllDependencies(type: DependencyReportTask) {}
}
或者,您也可以尝试“分级冲洗”。
Gradle FLUSH Cache
(Optional, but preferred). Close all instances of IntelliJ or any other Java IDE.
./gradlew --stop
OR
gradle --stop
(now delete the folders)
rm -rf $HOME/.gradle/caches/
rm -rf $HOME/.gradle/build-cache-tmp/
(now resume normal gradlew commands like:)
./gradlew clean build
或者,您也可以执行intelliJ“刷新”操作。
(tested with IntelliJ version 2020.1 or later)
Close IntelliJ.
Delete the ".idea" folder off of the root folder.
Re OPEN the project.
Wait for Gradle imports and indices rebuild to complete
Try the IDE build again.
And the big hammer: "Invalidate IntelliJ caches". see https://www.jetbrains.com/help/rider/Cleaning_System_Cache.html and/or https://www.jetbrains.com/help/idea/invalidate-caches.html
如果您正在使用Eclipse或NetBeans或其他,则必须找到“等效”。这个想法是IDE变得“混乱”。
奖金
多级模块:
https://stackoverflow.com/questions/70624098
复制相似问题