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

Gradle项目刷新时spring-native-0.10.0.jar下载401错误求助

问题描述

使用Gradle构建Java项目时触发以下错误:

Could not download spring-native-0.10.0.jar (org.springframework.experimental:spring-native:0.10.0)
Could not get resource 'https://repo.spring.io/release/org/springframework/experimental/spring-native/0.10.0/spring-native-0.10.0.jar'.
Could not GET 'https://repo.spring.io/release/org/springframework/experimental/spring-native/0.10.0/spring-native-0.10.0.jar'. Received status code 401 from server:

Possible solution:

  • Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

我并未在项目中直接引入org.springframework.experimental:spring-native:0.10.0依赖,却出现需要登录才能下载该Jar包的提示,请问遗漏了什么配置?该如何解决?

项目的build.gradle配置如下:

buildscript {
    apply from: "${rootProject.projectDir}/common.gradle"

    repositories {
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE"
        classpath "gradle.plugin.com.arenagod.gradle:mybatis-generator-plugin:1.4"
    }
}

plugins {
    id 'java'
    id 'idea'
    id 'java-library'
    id 'application'
    id 'maven-publish'
    id "org.springframework.boot" version "2.6.7"
    id "io.freefair.lombok" version "6.4.3"
    id 'com.github.ayltai.spring-graalvm-native-plugin' version '1.4.10'
    id "org.springdoc.openapi-gradle-plugin" version "1.3.4"

}

apply from: "${rootProject.projectDir}/common.gradle"

subprojects {
    apply plugin: 'io.freefair.lombok'
    apply plugin: 'java'
    apply plugin: 'maven-publish'
    apply plugin: 'java-library'
    apply plugin: "idea"
    apply plugin: "io.spring.dependency-management"
    apply plugin: 'org.springframework.boot'
    apply plugin: 'org.springdoc.openapi-gradle-plugin'


    configurations.all {
        // exclude group: "ch.qos.logback", module: "logback-classic"
        // exclude group: "ch.qos.logback", module: "logback-core"
        exclude group: "org.slf4j", module: "slf4j-simple"
        /** https://stackoverflow.com/questions/67484542/redis-command-timed-out-nested-exception-is-io-lettuce-core-rediscommandtimeout
         * https://stackoverflow.com/questions/73244405/java-lang-illegalargumentexception-unable-to-find-gatewayfilterfactory-with-nam
         * the spring gateway project needs to using lettuce
         * because the jedis did not support reactive until 2022.08
         * only lettuce support reactive
         * so we should not exclude the lettuce for the whole project
        **/
        // exclude group: "io.lettuce", module: "lettuce-core"
        /**
         * why exclude the gson?
         * https://github.com/swagger-api/swagger-core/issues/1826
         */
        // exclude group: "com.google.code.gson", module: "gson"

        // check for updates every build
        resolutionStrategy.cacheChangingModulesFor 0, 'seconds'

        // check for updates every build
        resolutionStrategy.cacheChangingModulesFor 0, 'seconds'

        resolutionStrategy {
            eachDependency { DependencyResolveDetails details ->
                if (details.requested.group == 'com.github.jsqlparser') {
                    details.useVersion "2.1"
                }
                if (details.requested.group == 'redis.clients' && details.requested.name == 'jedis' ) {
                    details.useVersion("3.8.0")
                }
                if (details.requested.group == 'org.springframework.data' && details.requested.name == 'spring-data-redis' ) {
                    details.useVersion("2.7.2")
                }
                //exclude group: "org.springframework.data", module: "spring-data-redis"
                if (details.requested.group == 'org.postgresql' && details.requested.name == 'postgresql' ) {
                    details.useVersion("42.2.23")
                }
                if (details.requested.group == 'org.apache.logging.log4j' && details.requested.name == 'log4j-api' ) {
                    details.useVersion("2.17.0")
                }
            }
        }
    }

    repositories {
        if (project.hasProperty("buildEnv") && project.getProperties().get("buildEnv") == "github") {
            mavenCentral()
        } else {
            mavenCentral()
        }
    }

    dependencies {
        compileOnly "org.projectlombok:lombok:${lombokVersion}"
        annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
        testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
        testImplementation "org.projectlombok:lombok:${lombokVersion}"
        api "$rootProject.ext.dependencies.log4j"
        api "$rootProject.ext.dependencies.collections4"
        api "org.apache.commons:commons-lang3:${commonColleciton3Version}"
        implementation "$rootProject.ext.dependencies.mybatisGeneratorCore"
        implementation "$rootProject.ext.dependencies.itfswMybatisGeneratorPlugin"
        testImplementation group: 'org.testng', name: 'testng', version: '7.4.0'
    }

    dependencyManagement {
        imports {
            mavenBom "org.springframework.cloud:spring-cloud-dependencies:$rootProject.ext.version.springCloudVersion"
        }
    }
}

allprojects {
    sourceCompatibility = 11
    targetCompatibility = 11
    def defaultEncoding = 'UTF-8'
    compileJava {
        options.encoding = defaultEncoding
    }
    compileTestJava {
        options.encoding = defaultEncoding
    }
    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
    }

    /**
     * remove aliyun repo config from ~/.gradle/init.gradle into project
     * avoid to force other project in machine use aliyun
     * some international project could not fetch dependencies from aliyun
     */
    repositories {
        def PROXY_REPOSITORY_URL = 'https://maven.aliyun.com/nexus/content/groups/public'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $PROXY_REPOSITORY_URL."
                    remove repo
                }
            }
        }
        maven {
            url PROXY_REPOSITORY_URL
        }
        /****** Release Repo ********/
        maven {
            credentials {
                username System.getenv("ALIYUN_REPO_USERNAME")
                password System.getenv("ALIYUN_REPO_PASSWORD")
            }
            url 'https://packages.aliyun.com/maven/repository/2236707-release-REsSq7/'
        }
        /****** Snapshot Repo ********/
        maven {
            credentials {
                username System.getenv("ALIYUN_DOCKER_REPO_USER_NAME")
                password System.getenv("ALIYUN_DOCKER_REPO_USER_PASSWORD")
            }
            url 'https://packages.aliyun.com/maven/repository/2236707-snapshot-lUlWG7/'
        }
    }
}
问题分析与解决

原因

这个spring-native依赖是由你引入的com.github.ayltai.spring-graalvm-native-plugin插件间接带入的。该插件用于构建GraalVM原生镜像,会自动关联Spring Native相关依赖。而spring-native 0.10.0属于早期版本,Gradle默认会尝试从Spring官方的repo.spring.io/release仓库下载,但该仓库现在需要认证,因此返回401错误。

解决方法

方法1:移除无用插件

如果你的项目不需要构建GraalVM原生镜像,直接删除该插件即可解决问题:
在plugins块中移除这一行:

id 'com.github.ayltai.spring-graalvm-native-plugin' version '1.4.10'

方法2:添加Spring仓库

如果确实需要使用该插件,需要在项目仓库配置中添加Spring官方仓库:
在allprojects的repositories块中加入:

maven {
    url 'https://repo.spring.io/release'
    // 若仓库需要认证,补充以下配置(通常release仓库公开可访问,若仍报错需确认权限)
    // credentials {
    //     username '你的用户名'
    //     password '你的密码'
    // }
}

方法3:升级插件版本

com.github.ayltai.spring-graalvm-native-plugin 1.4.10版本较旧,建议升级到兼容Spring Boot 2.6.7的最新版本。新版本可能会依赖更新的Spring Native组件(或不再需要单独引入spring-native,因为Spring Boot 2.4+已内置原生镜像支持),从而避免依赖需要认证的旧仓库。

额外排查建议

  • 执行gradle dependencies命令生成依赖树,确认spring-native的具体来源,方便精准处理。
  • 检查common.gradle文件,确认其中是否包含相关依赖或仓库配置,因为项目的buildscript和主项目都应用了该文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 14:55:55