You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Security在CLI与IntelliJ中构建失败求助

问题描述
  • 执行命令 ./gradlew publishToMavenLocal 时,:buildSrc:compileJava 任务执行失败,报错无法解析依赖 io.projectreactor:reactor-core:3.5.0-M6,访问 https://repo.spring.io/plugins-release 对应的pom文件时返回401未授权状态码。
  • 在IntelliJ中打开项目后,无法正常构建和完成代码索引。

预期结果:

  1. 执行 ./gradlew publishToMavenLocal 可成功完成构建
  2. IntelliJ中项目能正常构建并完成代码索引

项目buildscript的Gradle配置如下:

buildscript {
    dependencies {
        classpath "io.spring.javaformat:spring-javaformat-gradle-plugin:$springJavaformatVersion"
        classpath 'io.spring.nohttp:nohttp-gradle:0.0.10'
        classpath "io.freefair.gradle:aspectj-plugin:6.6-rc1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        classpath "com.netflix.nebula:nebula-project-plugin:8.2.0"
    }
    repositories {
        mavenCentral()
        maven { url 'https://repo.spring.io/milestone' }
        maven { url 'https://repo.spring.io/plugins-snapshot' }
        maven { url 'https://repo.spring.io/plugins-release-local' }
        maven { url 'https://plugins.gradle.org/m2/' }
    }
}
解决方案

1. 修正Gradle仓库配置

报错显示访问https://repo.spring.io/plugins-release返回401,说明该仓库需要认证,且当前buildscript的仓库列表中未配置此仓库(仅配置了plugins-release-local)。同时reactor-core:3.5.0-M6属于Spring里程碑版本,需从milestone仓库拉取,但依赖链中的部分插件可能需要从正确的Spring插件仓库获取。

修改buildscript的repositories块,添加https://repo.spring.io/plugins-release并配置认证信息(若有账号权限):

buildscript {
    dependencies {
        classpath "io.spring.javaformat:spring-javaformat-gradle-plugin:$springJavaformatVersion"
        classpath 'io.spring.nohttp:nohttp-gradle:0.0.10'
        classpath "io.freefair.gradle:aspectj-plugin:6.6-rc1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        classpath "com.netflix.nebula:nebula-project-plugin:8.2.0"
    }
    repositories {
        mavenCentral()
        maven { url 'https://repo.spring.io/milestone' }
        maven { url 'https://repo.spring.io/plugins-snapshot' }
        // 添加需要的Spring插件仓库并配置认证
        maven { 
            url 'https://repo.spring.io/plugins-release'
            credentials {
                username = '你的仓库账号'
                password = '你的仓库密码'
            }
        }
        maven { url 'https://plugins.gradle.org/m2/' }
    }
}

如果没有Spring仓库的认证账号,可尝试降低springJavaformatVersion至可从mavenCentral或milestone仓库获取的版本,避免依赖需要认证的插件仓库。

2. 修复IntelliJ构建与索引问题

  • 先在终端执行 ./gradlew clean build --refresh-dependencies 刷新依赖缓存,确保本地依赖拉取正常
  • 打开IntelliJ,进入File > Settings > Build, Execution, Deployment > Build Tools > Gradle,选择使用项目本地的Gradle版本(而非IntelliJ内置版本)
  • 执行File > Invalidate Caches...,选择Invalidate and Restart清除IntelliJ缓存并重启IDE

内容的提问来源于stack exchange,提问作者sujay hegde

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 18:10:17