Introduction
With the help of this maven-plugin you can create your own private Maven Repository with the essential features. There are many commercial products out there, for example: Nexus, JFrog and ets.., but the drawback is they required more resources (Compute and storage) and some are costly. Where you can simply setup in your AWS cloud with much much less cost.
New in v1.2.12: Upgraded to AWS SDK v2 with support for AWS SSO authentication!
New in v1.2.14: AWS Profile Support
Start Here
- Configure AWS Pre-Req
- Configure By AWS CLI (No ready yet)
- Configure By AWS Console
- Local PC Setup
- CI/CD Pipeline Setup
- Reference
Create IAM User, -Rule and -Policy.
You can use both AWS-CLI or Web Console (browser: https://aws.amazon.com/)
This plugin uses AWS SDK v2 which provides improved performance and supports modern authentication methods including AWS SSO.
The plugin supports multiple authentication methods (in order of priority):
- Static credentials in
settings.xml— explicit<username>/<password>(AWS access key + secret) - Named profile in
settings.xml—<profile>element pointing to a profile in~/.aws/config(supports SSO, assumed roles, etc.) - Environment variables —
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY - Default AWS credential chain — credentials file, EC2 instance profile, ECS task role, EKS web identity
| Element | Required | Description |
|---|---|---|
<region> |
Yes | AWS region, e.g. eu-central-1 |
<profile> |
No | AWS named profile from ~/.aws/config. Mutually exclusive with static credentials — profile is ignored when <username>/<password> are present. |
<publicRepository> |
No | Set to true to upload objects with public-read ACL. Default: false |
<endpoint> |
No | Custom S3-compatible endpoint URL |
<pathStyleEnabled> |
No | Enable path-style access. Required for some S3-compatible services. Default: false |
If you use AWS SSO or assume-role profiles, set <profile> instead of static credentials. Make sure the session is active before running Maven:
aws sso login --profile mavenNote: make sure that you have latest AWS CLI installed in your PC. Note: make sure that you are in your project root directory and have permission to create a file.
curl -s https://raw.githubusercontent.com/ehsaniara/maven-repository-aws-s3/master/aws-s3-setup.sh | bash /dev/stdin bucket_name username(browser: https://aws.amazon.com/)
Create a AWS S3 bucket, try to have unique name from you domain, for example: my-project-com-maven-repository
and also create 2 folder of release and snapshot in it.
Create policy with the following json (select json tab):
Note: dont forget to replace YOUR_BUCKET_NAME by your bucket name, for example: my-project-com-maven-repository
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:CreateBucket",
"s3:ListBucket",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}then give name to this policy. something similar to your bucket name, for example: my-project-com-maven-repository-policy and then create the policy.
on Add user, select a User name and make sure you have select the "Programmatic access"
then select "Attach existing policies directly", and in Filter policies box search for your the policy name you have just created.
then tag,review and create the user.
Important: Make sure that you have download the .csv file and store it in the secure place. the credentials in this file is required to user in your
~/.m2/setting.xmlfile
create a user with (Programmatic access).
- create separate user to access your S3 bucket, for the security reason you should not give admin permission. this user should have enough access to read and write in the bucket and no more than that.
If you plan to deploy your project jar from your local machine you need to follow the following steps.
- on your local maven setup directory
.m2add the following XML snaps insetting.xml. You basically give permission to maven to access the S3 bucket, to be able to push or pull the files. One for snapshot and one for release.
Use <username> and <password> to provide an IAM access key and secret directly:
<settings>
<servers>
<server>
<id>YOUR_BUCKET_NAME-snapshot</id>
<username>AWS_ACCESS_KEY_ID</username>
<password>AWS_SECRET_ACCESS_KEY</password>
<configuration>
<region>AWS_REGION</region>
<publicRepository>false</publicRepository>
</configuration>
</server>
<server>
<id>YOUR_BUCKET_NAME-release</id>
<username>AWS_ACCESS_KEY_ID</username>
<password>AWS_SECRET_ACCESS_KEY</password>
<configuration>
<region>AWS_REGION</region>
<publicRepository>false</publicRepository>
</configuration>
</server>
</servers>
</settings>If you authenticate via AWS SSO or a named profile in ~/.aws/config, omit <username>/<password> and use <profile> instead. The profile name must match an entry in your ~/.aws/config file.
<settings>
<servers>
<server>
<id>YOUR_BUCKET_NAME-snapshot</id>
<configuration>
<region>AWS_REGION</region>
<profile>YOUR_AWS_PROFILE_NAME</profile>
<publicRepository>false</publicRepository>
</configuration>
</server>
<server>
<id>YOUR_BUCKET_NAME-release</id>
<configuration>
<region>AWS_REGION</region>
<profile>YOUR_AWS_PROFILE_NAME</profile>
<publicRepository>false</publicRepository>
</configuration>
</server>
</servers>
</settings>For SSO profiles, make sure you have an active session before running Maven:
aws sso login --profile YOUR_AWS_PROFILE_NAME
mvn deployNote: If both
<username>/<password>and<profile>are present, static credentials take priority.
- on your project
pom.xmladd the following xml to let maven DOWNLOAD your project artifactory from the maven-repo
<repositories>
<repository>
<id>YOUR_BUCKET_NAME-snapshot</id>
<url>s3://YOUR_BUCKET_NAME/snapshot</url>
</repository>
<repository>
<id>YOUR_BUCKET_NAME-release</id>
<url>s3://YOUR_BUCKET_NAME/release</url>
</repository>
</repositories>
Note: make sure that<id>YOUR_BUCKET_NAME-snapshot</id> and <id>YOUR_BUCKET_NAME-release</id> should be identical with your .m2/setting.xml ids
- The following xml is required if you want ,user be able to upload into maven repo., from its terminal or idea
on your project
pom.xmladd the following xml to let maven UPLOAD your project artifactory into the maven-repo
<distributionManagement>
<snapshotRepository>
<id>YOUR_BUCKET_NAME-snapshot</id>
<url>s3://YOUR_BUCKET_NAME/snapshot</url>
</snapshotRepository>
<repository>
<id>YOUR_BUCKET_NAME-release</id>
<url>s3://YOUR_BUCKET_NAME/release</url>
</repository>
</distributionManagement>
And the most important one, add the following xml in your project pom.xml with in the <build> tag
<build>
...
<extensions>
<extension>
<groupId>com.github.ehsaniara</groupId>
<artifactId>maven-repository-aws-s3</artifactId>
<version>1.2.14</version>
</extension>
</extensions>
...
</build>for Example:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>com.github.ehsaniara</groupId>
<artifactId>maven-repository-aws-s3</artifactId>
<version>1.2.14</version>
</extension>
</extensions>
</build>once you have setup your pom.xml file in your project you can run the following line:
# to clean your target directory
mvn clean
# deploy your artifactory into you maven-repo (AWS S3 Bucket)
mvn deploy[updating soon..]
Apache wagon: http://maven.apache.org/wagon/

