【问题标题】:How do I deploy jars to S3 with maven?如何使用 Maven 将 jar 部署到 S3?
【发布时间】:2018-06-28 18:42:37
【问题描述】:

我有一个使用 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 已经很老了,并且使用过时的身份验证机制:

所以,我也尝试过:

<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": "*"
        }
    ]
}

【问题讨论】:

  • 您可以尝试将AWS_ACCESS_KEY_IDAWS_SECRET_KEY 设置为环境变量吗?看看它是否被捡起。
  • 您没有提到 s3 存储桶策略,您是否验证它是否限制了特定用户的上传,或强制加密或类似的东西?检查您是否能够直接上传到此存储桶而不使用 Maven 也是一个好主意。
  • 同时检查您是否在正确的 settings.xml 文件 mvn -X 中配置凭据
  • 如果扩展的年龄真的是原因,也许看看这个帖子stackoverflow.com/questions/33741584/…是值得的。
  • 你的问题在这里:Status Code: 403; Error Code: AccessDenied; Request ID: CE401778F4180C1E) ,,,

标签: java maven amazon-web-services amazon-s3


【解决方案1】:

这有帮助吗?

  <servers>
    <server>
      <id>BUCKET_NAME.release</id>
      <username>ACCESSKEYID</username>
      <password>SECRETACCESSKEY</password>
      <filePermissions>BucketOwnerFullControl</filePermissions>
    </server>
    <server>
       <id>BUCKET_NAME.snapshot</id>
       <username>ACCESSKEYID</username>
       <password>SECRETACCESSKEY</password>
       <filePermissions>BucketOwnerFullControl</filePermissions>
    </server>
  </servers>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    相关资源
    最近更新 更多