为什么我们的Maven S3 wagon配置突然无法正常使用?
问题说明
我们有一个托管在AWS S3上的自定义Maven仓库,已经稳定使用多年,最近突然出现故障。配置完全遵循公司内部文档:~/.m2/settings.xml配置内容如下:
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <servers> <server> <id>company-s3-release-repo</id> <username>AKxxxxxxxxxxxxxxxx4A</username> <password>sFxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxRI/8xxS</password> </server> <server> <id>company-s3-snapshot-repo</id> <username>AKxxxxxxxxxxxxxxxx4A</username> <password>sFxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxRI/8xxS</password> </server> </servers> <profiles> <profile> <id>default</id> <repositories> <repository> <releases> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>company-s3-release-repo</id> <name>company AWS Release Repository</name> <url>s3://maven.company.de/release</url> </repository> <repository> <releases> <enabled>false</enabled> </releases> <snapshots> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> <id>company-s3-snapshot-repo</id> <name>company AWS Snapshot Repository</name> <url>s3://maven.company.de/snapshot</url> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>default</activeProfile> </activeProfiles> </settings>
wagon通过项目下的.mvn/extensions.yml配置:
<?xml version="1.0" encoding="UTF-8"?> <extensions> <extension> <groupId>org.springframework.build</groupId> <artifactId>aws-maven</artifactId> <version>5.0.0.RELEASE</version> </extension> </extensions>
使用mvn -B dependency:get命令从仓库下载构件时失败,报错信息如下:
$ mvn -B dependency:get -Dtransitive=false -Dartifact=de.company.artifact:artifact:6.0.4 [INFO] Scanning for projects... [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] --- maven-dependency-plugin:2.8:get (default-cli) @ standalone-pom --- [INFO] Resolving de.company.artifact:artifact:jar:6.0.4 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.265 s [INFO] Finished at: 2021-10-08T09:37:07+02:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:get (default-cli) on project standalone-pom: Couldn't download artifact: Could not transfer artifact de.company.artifact:artifact:jar:6.0.4 from/to company-s3-release-repo (s3://maven.company.de/release): Cannot access s3://maven.company.de/release with type default using the available connector factories: BasicRepositoryConnectorFactory [ERROR] de.company.artifact:artifact:jar:6.0.4 [ERROR] [ERROR] from the specified remote repositories: [ERROR] company-s3-release-repo (s3://maven.company.de/release, releases=true, snapshots=false), [ERROR] company-s3-snapshot-repo (s3://maven.company.de/snapshot, releases=false, snapshots=true), [ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false): Cannot access s3://maven.company.de/release using the registered transporter factories: WagonTransporterFactory: Unsupported transport protocol s3: java.util.NoSuchElementException [ERROR] role: org.apache.maven.wagon.Wagon [ERROR] roleHint: s3 [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
使用的Maven版本为3.8.2:
$ mvn --version Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f) Maven home: /usr/local/Cellar/maven/3.8.2/libexec Java version: 17, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/17/libexec/openjdk.jdk/Contents/Home Default locale: en_DE, platform encoding: UTF-8 OS name: "mac os x", version: "11.6", arch: "x86_64", family: "mac"
已尝试在.mvn/extensions.yml中更换其他wagon配置,包括com.allogy.maven.wagon.maven-s3-wagon:1.2.0和org.zalando.org.springframework.build.aws-maven:5.0.0.RELEASE-zal-2,均报相同错误,问题没有解决。
故障原因与解决方案
核心报错为Maven无法识别s3传输协议,说明S3 wagon扩展没有被正常加载,对应三个直接原因:
- 扩展配置格式错误:
.mvn/extensions.yml是YAML格式配置文件,你当前配置写的是XML格式,Maven无法解析,自然不会加载wagon扩展。
正确的extensions.yml配置如下:
如果你习惯用XML格式配置扩展,需要把文件名改为extensions: - groupId: org.springframework.build artifactId: aws-maven version: 5.0.0.RELEASEextensions.xml放在.mvn目录下。 - 执行命令的工作目录错误:项目级的
.mvn配置仅在对应项目的根目录执行Maven命令时生效,你执行dependency:get时如果是在无项目的空目录,Maven会启动无POM的独立模式,不会读取项目级的扩展配置。
如果需要全局支持S3 wagon,可以把对应wagon的JAR包放到Maven安装目录的lib/ext路径下,对所有项目生效。 - 版本兼容性问题:你使用的
org.springframework.build:aws-maven:5.0.0.RELEASE已经停止维护,不兼容Java 17和Maven 3.8.x版本。推荐换用仍在维护的s3 wagon实现:extensions: - groupId: com.github.seahen artifactId: maven-s3-wagon version: 1.3.5
内容的提问来源于stack exchange,提问作者oschlueter
相关产品推荐
相关产品推荐

