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

Gradle构建阶段访问S3对象时出现Access Denied错误求助

S3 Maven仓库Gradle构建403权限问题

我用指定profile在终端和AWS Toolkit中均可正常访问S3存储桶,能下载目标文件,IAM用户已配置AmazonS3FullAccess权限及自定义策略。但执行gradle build时,无法解析存储桶中的org.egeiper.qaBase:QA-Base:1.0.7依赖,报S3 Access Denied(403)错误,无论存储桶是否开启公共访问,问题均存在。


终端成功下载命令

$ aws s3 cp s3://maven.egeiper/org/egeiper/qaBase/QA-Base/1.0.7/QA-Base-1.0.7.pom . --profile egeiper

download: s3://maven.egeiper/org/egeiper/qaBase/QA-Base/1.0.7/QA-Base-1.0.7.pom to ./QA-Base-1.0.7.pom

Gradle构建错误信息

> A problem occurred configuring root project 'QA-Base'.
 Could not resolve all files for configuration ':classpath'.
   Could not resolve org.egeiper.qaBase:QA-Base:1.0.7.
     Required by:
         project :
      Could not resolve org.egeiper.qaBase:QA-Base:1.0.7.
         > Could not get resource 's3://maven.egeiper/org/egeiper/qaBase/QA-Base/1.0.7/QA-Base-1.0.7.pom'.
            > Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: N2RS6X0XMFFQ34XR; S3 Extended Request ID: XqYfJ09KVk7Z/LUmF6kdegaGkPgYXKCy+bukM9NHSWJSYmNrfIh2A/qEmpQLQfh7DuhE2mpl/iJaLxlvPtcjqg==; Proxy: null)

AWS配置信息

AWS Toolkit存储桶状态

截图显示可在AWS Toolkit中正常查看s3://maven.egeiper存储桶及目标文件路径。

.aws/credentials文件

截图显示文件中已配置egeiper profile的AWS访问密钥和密钥ID。

.aws/config内容

[profile egeiper]
region = eu-central-1
output = json

IAM自定义策略

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::maven.egeiper"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::maven.egeiper/*"
            ]
        }
    ]
}

build.gradle完整内容

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "s3://maven.egeiper"
            authentication {
                awsIm(AwsImAuthentication)
            }
        }
    }
    dependencies {
        classpath 'com.github.ksoichiro:gradle-console-reporter:0.6.3'
        classpath 'org.egeiper.qaBase:QA-Base:1.0.7'
    }
}
plugins {
    id 'java'
    id "com.github.spotbugs" version "5.0.13"
    id 'pmd'
    id 'checkstyle'
    id 'maven-publish'
}

group 'org.egeiper.qaBase'
version '1.0.7'
repositories {
    mavenCentral()
    maven {
        url "s3://maven.egeiper"
        authentication {
            awsIm(AwsImAuthentication)
        }
    }
}

java {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
}


dependencies {
    implementation 'org.seleniumhq.selenium:selenium-java:4.7.2'
    implementation 'org.testng:testng:7.4.0'
    implementation 'io.qameta.allure:allure-testng:2.19.0'
    implementation 'io.rest-assured:rest-assured:5.3.0'
    implementation 'org.awaitility:awaitility:4.2.0'
    compileOnly 'org.projectlombok:lombok:1.18.24'
    annotationProcessor 'org.projectlombok:lombok:1.18.24'
    implementation 'org.aeonbits.owner:owner:1.0.12'
    implementation 'org.seleniumhq.selenium:selenium-chrome-driver:4.7.2'
    implementation 'org.seleniumhq.selenium:selenium-firefox-driver:4.7.2'
}

pmd {
    consoleOutput = true
    toolVersion = "6.21.0"
    rulesMinimumPriority = 5
    ruleSetConfig = rootProject.resources.text.fromFile("config/pmdRules.xml")
    ruleSets = []
}

checkstyle {
    toolVersion = "8.23"
    configFile = rootProject.file('config/checkstyle.xml')
}

publishing {
    repositories {
        maven {
            url "s3://maven.egeiper"
            authentication {
                awsIm(AwsImAuthentication)
            }
        }
    }
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }

}

test {
    useTestNG()
    maxParallelForks = Runtime.runtime.availableProcessors()
}

内容的提问来源于stack exchange,提问作者Ege İper

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 15:35:20