AWS CodeArtifact - separate repositories for test and production environments

150 views Asked by At

We recently built a core JPA layer application that we manage on AWS CodeArtifact. We have multiple applications that consume this jar. No problem there. Management wants separate repositories for test and production. But upon research using phind (chat GPT) states that

"When using AWS CodeArtifact to share a jar across multiple applications, it is generally recommended to use the same repository for both test and production."

I was inclined to think the same way, but management wants them separated.

Our applications are maven/spring boot. The repositories and other AWS config stuff are configured in settings.xml. I would be switching between repos depending on the spring.profiles.active property.

First, would like the opinions on which way to go and/or any sample code for your configuration.

1

There are 1 answers

0
Bradley D On

Was able to solve this by doing this in pom.xml:

<distributionManagement>
    <repository>
        <id>backend-prod</id>
        <name>Production Repository</name>
        <url>https://mydomain-XXXXXXXXXXXX.d.codeartifact.us-east-1.amazonaws.com/maven/backend-prod/</url>
    </repository>
    <snapshotRepository>
        <id>backend-test</id>
        <name>Test Repository</name>
        <url>https://mydomain-XXXXXXXXXXXX.d.codeartifact.us-east-1.amazonaws.com/maven/backend-test/</url>
    </snapshotRepository>
</distributionManagement>

With the above, maven will look for a version with -SNAPSHOT appended. So in our build bash script, we are already checking for ENV, which is either 'test' or 'prod'. If test, then we append -SNAPSHOT to the version and maven handles the rest - uploading the artifact to the snapshotRepository