2

We are attempting to integrate Maven with AWS' CodeArtifact.

I believe that we have properly followed the "Use CodeArtifact with mvn" directions.

However, when I attempt to perform a mvn clean compile from inside of Intellij we get the following exception:

[DEBUG] Failed to decrypt password for server codeartifact: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: java.io.FileNotFoundException: /Users/hooknc/.m2/settings-security.xml (No such file or directory)
org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: java.io.FileNotFoundException: /Users/nhook/.m2/settings-security.xml (No such file or directory)
    at org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher.decrypt (DefaultSecDispatcher.java:121)
    at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt (DefaultSettingsDecrypter.java:114)
    at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt (DefaultSettingsDecrypter.java:70)
    at org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory.newRepositorySession (DefaultRepositorySystemSessionFactory.java:167)
    at org.apache.maven.DefaultMaven.newRepositorySession (DefaultMaven.java:350)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:185)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: java.io.FileNotFoundException: /Users/hooknc/.m2/settings-security.xml (No such file or directory)
    at org.sonatype.plexus.components.sec.dispatcher.SecUtil.read (SecUtil.java:69)
    at org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher.getSec (DefaultSecDispatcher.java:206)
    at org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher.decrypt (DefaultSecDispatcher.java:90)
    at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt (DefaultSettingsDecrypter.java:114)
    at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt (DefaultSettingsDecrypter.java:70)
    at org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory.newRepositorySession (DefaultRepositorySystemSessionFactory.java:167)
    at org.apache.maven.DefaultMaven.newRepositorySession (DefaultMaven.java:350)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:185)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: java.io.FileNotFoundException: /Users/hooknc/.m2/settings-security.xml (No such file or directory)
    at java.io.FileInputStream.open0 (Native Method)
    at java.io.FileInputStream.open (FileInputStream.java:195)
    at java.io.FileInputStream.<init> (FileInputStream.java:138)
    at org.sonatype.plexus.components.sec.dispatcher.SecUtil.toStream (SecUtil.java:100)
    at org.sonatype.plexus.components.sec.dispatcher.SecUtil.read (SecUtil.java:56)
    at org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher.getSec (DefaultSecDispatcher.java:206)
    at org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher.decrypt (DefaultSecDispatcher.java:90)
    at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt (DefaultSettingsDecrypter.java:114)
    at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt (DefaultSettingsDecrypter.java:70)
    at org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory.newRepositorySession (DefaultRepositorySystemSessionFactory.java:167)
    at org.apache.maven.DefaultMaven.newRepositorySession (DefaultMaven.java:350)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:185)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)

With the final cause being Caused by: java.io.FileNotFoundException: /Users/hooknc/.m2/settings-security.xml (No such file or directory)

Here is the contents of a settings.xml file that is stored in ~/.m2/:

<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 https://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository/>
    <interactiveMode/>
    <offline/>
    <pluginGroups/>
    <servers>
      <server>
        <id>codeartifact</id>
        <username>aws</username>
        <password>${env.CODEARTIFACT_AUTH_TOKEN}</password>
      </server>
    </servers>
    <mirrors>
      <mirror>
        <id>codeartifact</id>
        <name>domain--repository</name>
        <url>https://domain-<secret_number>.d.codeartifact.us-west-2.amazonaws.com/maven/repository/</url>
        <mirrorOf>*</mirrorOf>
      </mirror>
    </mirrors>
    <proxies/>
    <profiles>
      <profile>
        <id>codeartifact</id>
        <activation>
          <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
          <repository>
            <id>codeartifact</id>
            <url>https://domain-<secret_number>.d.codeartifact.us-west-2.amazonaws.com/maven/repository/</url>
          </repository>
        </repositories>
      </profile>
    </profiles>
    <activeProfiles/>
</settings>

We then run the AWS command to get a token to access CodeArtifact:

export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --profile hooknc --domain domain --domain-owner <secret_number> --query authorizationToken --output text`

Which should set the environment variable CODEARTIFACT_AUTH_TOKEN, which should get picked up by the settings.xml value ${env.CODEARTIFACT_AUTH_TOKEN}

So, my question is, how do I disable the usage of Maven's Password Encryption while using Intillij?

Thank you for your time.

hooknc
  • 4,854
  • 5
  • 31
  • 60
  • `We then run the AWS command to get a token to access CodeArtifact: ... Which should set the environment variable` Note that the IDE restart might be needed in order for IDE to pick up new environment variables. – Andrey Nov 02 '20 at 08:09
  • Have you tried - does it work from command line Maven? – Andrey Nov 02 '20 at 08:10
  • @Andrey x2... I restarted my ide and it still did not work. I then ran the following command `echo $CODEARTIFACT_AUTH_TOKEN` from the intellij command line and it returned nothing. So I ran the `export CODEARTIFACT_AUTH_TOKEN='aws codeartifact get-authorization-token ...` command from intellij's terminal. I still get authorization denied. I do not have command line maven installed because I am using intellij and it has maven integrated into it. – hooknc Nov 02 '20 at 17:09
  • The point is to verify if it is an issue with the IDE or with Maven configuration. Can you check this with command line Maven? – Andrey Nov 09 '20 at 11:55
  • Was this ever resolved? If so, could you paste your answer? Thanks! – Brandon Dec 04 '21 at 16:30
  • @Brandon No, we never resolved this issue. We ended up punting on using aws-codeartifact. We decided to use [github packages](https://docs.github.com/en/packages/learn-github-packages/introduction-to-github-packages) instead. – hooknc Dec 06 '21 at 16:49
  • This should be a Maven/IntelliJ issue due to your password being inside "{..}'. Since Maven 2.2 or so you can encrypt passwords in the settings.xml and mark it with "{...}" which in turn will be decrypted by the master key in the settings-security.xml (https://maven.apache.org/guides/mini/guide-encryption.html). Since you don't use that functionality, you don't have this file and therefore you get this "File not found" error. Unfortunately I cannot tell you how to fix that, because I also have this issue and found your topic here – kinglite Jul 20 '22 at 13:25

2 Answers2

0

@hooknc in your question, you correctly use backticks:

export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token ...`

but in your comment you're using single quotes:

export CODEARTIFACT_AUTH_TOKEN='aws codeartifact get-authorization-token ...'

my guess is that the former is a copy-paste from the docs to SO but the latter was erroneously copied by hand into your editor.

I suggest replacing the backticks with the modern notation of "$(...)" notation to reduce confusion (plus it supports nesting):

export CODEARTIFACT_AUTH_TOKEN="$(aws codeartifact get-authorization-token ...)"
333kenshin
  • 1,995
  • 12
  • 17
0

The problem here it's a know bug on IntelliJ IDEA that Maven plugin cannot resolve environment variables.

Try to export the token from the command line and run "mvn clean compile" at this terminal, outside IntelliJ and it works.

Know bugs:

https://youtrack.jetbrains.com/issue/IDEA-205484/IDE-does-not-evaluate-environment-variables-from-Maven-user-settings-file

https://youtrack.jetbrains.com/issue/IDEA-96358