【问题标题】:Could not find org.springframework.boot:spring-boot-dependencies:2.6.1找不到 org.springframework.boot:spring-boot-dependencies:2.6.1
【发布时间】:2022-01-07 16:10:30
【问题描述】:

我按照here 的说明获取最新的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

【问题讨论】:

    标签: spring-boot gradle


    【解决方案1】:

    这是一个完整的文件作为示例:(这是 ROOT build.gradle)(如果您编写单体应用程序,您将只有一个 root 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”

    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 "FLUSH"

    (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 变得“混乱”。

    奖金

    多 Gradle 模块:

    https://docs.gradle.org/current/samples/sample_building_java_applications_multi_project.html

    【讨论】:

      【解决方案2】:

      感谢上面的@granadaCoder,在将 Gradle 重新安装到最新版本 7.3.3 后,实际问题是第二个存储库设置已经潜入我的 build.gradle

      repositories {
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
      }
      

      这正是错误表明未找到依赖项的地方。我把它改成了

      repositories {
        mavenCentral()
      }
      

      然后事情就开始起作用了。

      【讨论】:

      • SOF 礼仪是......“在你弄清楚之后”,你将其中一个答案标记为“答案”,以阻止这个问题出现为“未回答”。
      • 这就是为什么我认为提供“完整”内容是更好的最佳实践......但对于我的回答......但也适用于您最初的问题。 #lessonsLearned 在这个问题之外,当 Java 开发人员没有在答案和问题上都输入导入语句时,它让我抓狂。
      • 是的,我没有给出完整的错误描述,应该被标记下来:-(问题现在更新了。
      猜你喜欢
      • 2021-05-18
      • 1970-01-01
      • 2022-01-07
      • 2023-02-07
      • 2021-03-29
      • 2021-10-30
      • 2021-03-05
      • 2016-05-24
      • 2020-08-15
      相关资源
      最近更新 更多