21

I'm currently storing my maven credentials in ~/.m2/settings.xml:

<server>
  <id>my_server_id</id>
  <username>my_username</username>
  <password>my_password</password>
</server>

However, I'm not satisfied with having the password in clear text, since the password is used for other services, so I'd rather prompt the user for the password when doing a mvn deploy. I'm deploying to a Nexus OSS install via https.

I know that the password can be encrypted, but since the encryption is reversible, this solution is not appropriate for my case.

Is there a way to make Maven prompt for a password when doing an https deploy?

rodrigorgs
  • 855
  • 2
  • 9
  • 20
  • 1
    If you're deploying to the Maven Central Repository (or using Nexus Pro) you may want to look into authenticating with a [User Token](http://blog.sonatype.com/2012/08/securing-repository-credentials-with-nexus-pro-user-tokens/) instead of username & password. – dnault Aug 30 '17 at 18:47

3 Answers3

14

As mentioned this functionality is currently not supported in the plugin. Issue MDEPLOY-51 actually asks for this improvement:

Allow the user to supply a user name password for a remote server when the deploy goal is called. Currently you have to add the repository username and password to the server.xml file. It would be helpful if the user could be prompted for a username and password on the command line. The password should be hidden when it is entered.

I would suggest voting for this improvement, or possibly implement the functionality yourself.

YMomb
  • 2,366
  • 1
  • 27
  • 36
ebo
  • 2,717
  • 1
  • 27
  • 22
2

The maven-deploy-plugin doesn't have an interactive mode, so no, you can't do this easily. The usual approach is to encrypt the credentials in your settings.xml file.

If you really feel you need this feature, you can always checkout the sources of the plugin and add interactive mode yourself and then contribute it back to the community.

carlspring
  • 31,231
  • 29
  • 115
  • 197
2

As an alternative to querying the user at run time, you can pass the username and password as args.

Try this mvn whatevergoal -Dusername -Dpassword

then inside the pom.xml ${username} and ${password}

squishy
  • 61
  • 5
  • 1
    This doesn't work because the username/password are in `settings.xml`, not `pom.xml`, and property substitution is disabled there. – benschumacher Nov 01 '17 at 22:10