AWS CodeArtifact is one of the AWS devops feature for package management. Even compare with NexusOSS, it cannot upload package manually, but it still worth to use if using AWS as DevOps Platform.In this demo, it will show how to config Java project (Maven / Gradle) to publish to CodeArtifact.
- Create AWS CodeArtifact Domain.
In AWS CodeArtifact, select Domains > Create Domain. Input domain name and click button Create Domain.
- Create Repository.
In AWS CodeArtifact, select Repository > Create Repository, input Repository name and click Next.
- Select Repository’s domain.
Select AWS account to This AWS account and select related Domain, then click Next.
- Confirm repository settings and create.
After review settings, then click Create Repository.
- Setup Maven repository settings for local computer
Create file setting.xml in %USER%\.m2\<settings> <servers> <server> <id>CodeArtifact</id> <username>aws</username> <password>${env.CODEARTIFACT_AUTH_TOKEN}</password> </server> </servers> <mirrors> <mirror> <id>CodeArtifact</id> <name>CodeArtifact</name> <url>https://{{domain-name}}-{{domain-id}}.d.codeartifact.ap-southeast-1.amazonaws.com/maven/{{repo-name}}/</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors> </settings>
- Generate AWS authentication token and store in variable.
In command prompt / bash, execute command and store variable in CODEARTIFACT_AUTH_TOKEN.:: For Windows: FOR /F "tokens=*" %a in ('aws codeartifact get-authorization-token --domain {{domain-name}} --domain-owner {{domain-id}} --query authorizationToken --output text') do SET CODEARTIFACT_AUTH_TOKEN=%a :: For Linux: export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain {{domain-name}} --domain-owner {{domain-id}} --query authorizationToken --output text`
- Update project settings.
Edit pom.xml (for Maven project) / build.gradle (for Gradle project).
pom.xml<project> ... <groupId>com.test</groupId> <artifactId>demo</artifactId> <version>1.0.1</version> <packaging>jar</packaging> <name>demo</name> ... <distributionManagement> <repository> <id>d-sg-2--d-sg-ca-repo</id> <name>aws-codeArtifact</name> <url>https://{{domain-name}}-{{domain-id}}.d.codeartifact.ap-southeast-1.amazonaws.com/maven/{{repo-name}}/</url> </repository> </distributionManagement> ... </project>
build.gradle
... plugins { id 'maven-publish' } ... ext { // Package metadata. packageGroup = 'com.test' artifact='demo' packageName = 'demo' packageVersion = '1.0.1' } ... repositories { //mavenCentral() //mavenLocal() maven { url 'https://{{domain-name}}-{{domain-id}}.d.codeartifact.ap-southeast-1.amazonaws.com/maven/{{repo-name}}/' credentials { username "aws" password System.env.CODEARTIFACT_AUTH_TOKEN } } } ... publishing { publications { mavenJava(MavenPublication) { groupId="${packageGroup}" artifactId="${packageName}" version="${packageVersion}" from components.java } } repositories { // AWS CodeArtifact maven { url 'https://{{domain-name}}-{{domain-id}}.d.codeartifact.ap-southeast-1.amazonaws.com/maven/{{repo-name}}/' credentials { username "aws" password System.env.CODEARTIFACT_AUTH_TOKEN } } } } ...
- Publish to AWS CodeArtifact.
In command prompt / bash, execute command.::Maven project. mvn deploy ::Gradle project. gradle publish
- Verify delivery.
In CodeArtifact, click Repositories > select repository, see published package found or not.
Leave a Reply