0

We've started using an AWS CodeArtifact Maven repository. Before connecting, developers must run a command ("aws") to acquire a temporary access token. How can I configure Maven to acquire and use this token automatically, without requiring running a script, configuring an IDE or changing the simple command line "mvn install"?

Maybe there's a trick I'm overlooking.

The token must be "interpolated" in the element <server>/<password> in settings.xml. This file will pre-process either an environment variable ({$env.token}) or a Java system property ({$token}). It will not process a project property.

  • The repository password cannot be specified within the POM file.
  • The settings.xml file cannot use project properties.
  • The exec-maven-plugin cannot set an environment variable in the parent process (Windows). It can write to a file.
  • The properties-maven-plugin cannot set a dynamic system property (e.g., from a file or script output).
  • The surefire plugin binds to the test phase and forks a JVM.
  • The Windows setx command does not affect the running process.

UPDATE: Maven downloads repository metadata before the first phase, so no plugin will solve the problem.

Steve Mitchell
  • 1,895
  • 1
  • 15
  • 12
  • 1
    Have you already taken a look at [AWS CodeArtifact Maven Proxy](https://github.com/unbroken-dome/aws-codeartifact-maven-proxy)? – Andrey B. Panfilov Oct 05 '22 at 03:38
  • I'm fascinated that somebody else has thought about the problem and created a solution. Make it an answer and I'll accept it. Though, a more convenient solution would be a wagon that sets certain system properties, including a TTL, from a shell script. That would work with AWS SSO as well. – Steve Mitchell Oct 05 '22 at 11:26
  • well, there is wagon extension on GH: https://github.com/OneGeek/codeartifact-maven-wagon – Andrey B. Panfilov Oct 05 '22 at 17:29
  • That's better. No configuration is needed in settings.xml and the token is not written to a file. However, it connects to AWS twice for every repository access. It's open source and simple code, so caching could be added. Thanks! – Steve Mitchell Oct 06 '22 at 07:27

0 Answers0