如何使用 maven 将 jar 部署到 S3?
2022-09-02 11:00:01
我有一个使用 Maven 进行构建的项目,我需要将其发布到私有 S3 存储库。
我发现了 AWS Maven Wagon,但当我尝试部署时,我收到身份验证错误:
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ custom-file-extension-windows-bundler ---
Downloading from aws-snapshot: s3://project-x-support/maven2/de/dynamicfiles/projects/javafx/bundler/custom-file-extension-windows-bundler/1.0.1-SNAPSHOT/maven-metadata.xml
Uploading to aws-snapshot: s3://project-x-support/maven2/de/dynamicfiles/projects/javafx/bundler/custom-file-extension-windows-bundler/1.0.1-SNAPSHOT/custom-file-extension-windows-bundler-1.0.1-20180119.133946-1.jar
Uploading to aws-snapshot: s3://project-x-support/maven2/de/dynamicfiles/projects/javafx/bundler/custom-file-extension-windows-bundler/1.0.1-SNAPSHOT/custom-file-extension-windows-bundler-1.0.1-20180119.133946-1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.773 s
[INFO] Finished at: 2018-01-19T13:39:46Z
[INFO] Final Memory: 23M/254M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project custom-file-extension-windows-bundler: Failed to deploy artifacts: Could not transfer artifact de.dynamicfiles.projects.javafx.bundler:custom-file-extension-windows-bundler:jar:1.0.1-20180119.133946-1 from/to aws-snapshot (s3://project-x-su
pport/maven2): Cannot write directory 'maven2/': Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: CE401778F4180C1E) -> [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
我很确定凭证和权限是正确的,因为我使用它们来部署带有Gradle的jar(我从.aws/credentials复制到.m2/settings.xml)。我的完整文件如下所示:pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.dynamicfiles.projects.javafx.bundler</groupId>
<artifactId>custom-file-extension-windows-bundler</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<developers>
<developer>
<name>Danny Althoff</name>
<email>fibrefox@dynamicfiles.de</email>
<url>https://www.dynamicfiles.de</url>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<version.java.source>1.8</version.java.source>
<version.java.target>1.8</version.java.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${version.java.source}</source>
<target>${version.java.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<display_version>${display_version}</display_version>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.springframework.build</groupId>
<artifactId>aws-maven</artifactId>
<version>5.0.0.RELEASE</version>
</extension>
</extensions>
</build>
<dependencies>
<dependency>
<groupId>javafx-packager</groupId>
<artifactId>javafx-packager</artifactId>
<version>1.8.0_40</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>aws-release</id>
<name>AWS Release Repository</name>
<url>s3://project-x-support/maven2</url>
</repository>
<snapshotRepository>
<id>aws-snapshot</id>
<name>AWS Snapshot Repository</name>
<url>s3://project-x-support/maven2</url>
</snapshotRepository>
</distributionManagement>
</project>
我注意到AWS Maven Wagon已经很旧了,并且使用了过时的身份验证机制:
- https://github.com/spring-projects/aws-maven/issues/48
- https://github.com/spring-projects/aws-maven/issues/44
- https://github.com/spring-projects/aws-maven/issues/50
所以,我也尝试了:
<groupId>org.zalando.org.springframework.build</groupId>
<artifactId>aws-maven</artifactId>
<version>5.0.0.RELEASE-zal-2</version>
但我得到同样的结果。
我的凭据是在 C:\Users\pupeno.m2\settings 中配置的.xml如下所示:
<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>aws-release</id>
<username>BLAHBLAH</username>
<password>SECRETBLAHBLAH</password>
</server>
<server>
<id>aws-snapshot</id>
<username>BLAHBLAH</username>
<password>SECRETBLAHBLAH</password>
</server>
</servers>
</settings>
我的相关政策如下所示:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutAnalyticsConfiguration",
"s3:GetObjectVersionTagging",
"s3:CreateBucket",
"s3:ReplicateObject",
"s3:GetObjectAcl",
"s3:DeleteBucketWebsite",
"s3:PutLifecycleConfiguration",
"s3:GetObjectVersionAcl",
"s3:PutObjectTagging",
"s3:DeleteObject",
"s3:GetIpConfiguration",
"s3:DeleteObjectTagging",
"s3:GetBucketWebsite",
"s3:PutReplicationConfiguration",
"s3:DeleteObjectVersionTagging",
"s3:GetBucketNotification",
"s3:PutBucketCORS",
"s3:GetReplicationConfiguration",
"s3:ListMultipartUploadParts",
"s3:PutObject",
"s3:GetObject",
"s3:PutBucketNotification",
"s3:PutBucketLogging",
"s3:GetAnalyticsConfiguration",
"s3:GetObjectVersionForReplication",
"s3:GetLifecycleConfiguration",
"s3:ListBucketByTags",
"s3:GetInventoryConfiguration",
"s3:GetBucketTagging",
"s3:PutAccelerateConfiguration",
"s3:DeleteObjectVersion",
"s3:GetBucketLogging",
"s3:ListBucketVersions",
"s3:ReplicateTags",
"s3:RestoreObject",
"s3:ListBucket",
"s3:GetAccelerateConfiguration",
"s3:GetBucketPolicy",
"s3:GetObjectVersionTorrent",
"s3:AbortMultipartUpload",
"s3:PutBucketTagging",
"s3:GetBucketRequestPayment",
"s3:GetObjectTagging",
"s3:GetMetricsConfiguration",
"s3:DeleteBucket",
"s3:PutBucketVersioning",
"s3:ListBucketMultipartUploads",
"s3:PutMetricsConfiguration",
"s3:PutObjectVersionTagging",
"s3:GetBucketVersioning",
"s3:GetBucketAcl",
"s3:PutInventoryConfiguration",
"s3:PutIpConfiguration",
"s3:GetObjectTorrent",
"s3:PutBucketWebsite",
"s3:PutBucketRequestPayment",
"s3:GetBucketCORS",
"s3:GetBucketLocation",
"s3:ReplicateDelete",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::project-x-support/*",
"arn:aws:s3:::project-x-support"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:HeadBucket",
"s3:ListObjects"
],
"Resource": "*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "s3:GetBucketLocation",
"Resource": "*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "*"
}
]
}