Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass a password in Maven Deploy in the command line?

This is the way it currently works, and it's the Maven Deploy Plugin Usage

pom.xml

[...]   <distributionManagement>     <repository>       <id>internal.repo</id>       <name>MyCo Internal Repository</name>       <url>Host to Company Repository</url>     </repository>   </distributionManagement> [...] 

settings.xml

[...]     <server>       <id>internal.repo</id>       <username>someUser</username>       <password>somePassword</password>     </server> [...] 

and what I'm trying to achieve is finding a way in which the username and password are typed in at the command line. to achieve mvn deploy -someUser -somePassword

like image 907
stef52 Avatar asked Jan 21 '15 16:01

stef52


People also ask

What is the use of mvn deploy command in Maven?

The mvn deploy runs the deploy plugin which deploys an artifact to the remote repository. A project may include the main jar and associated sources and Javadoc jars. The sources jar contains the Java sources, and the Javadoc jar contains the generated Javadoc.

What is Maven deploy command?

mvn deploy. This command invokes the deploy phase: deploy : copies the final package to the remote repository for sharing with other developers and projects.

How does maven deploy work?

deploy:deploy is used to automatically install the artifact, its pom and the attached artifacts produced by a particular project. Most if not all of the information related to the deployment is stored in the project's pom. deploy:deploy-file is used to install a single artifact along with its pom.

What are the settings you need to do before running mvn deploy?

Using the maven-deploy-plugin We need to specify the version and plugin in the <pluginManagement> tag of the pom. xml file to define the version of the plugin in parent pom and specify the version and plugin in the plugins section of the pom file to use the goals of the plugin by your project or your parent project.


2 Answers

The settings.xml is considered personal, so for that reason the username+password are stored in the (user-)settings.xml. So in general there's no reason to pass them as argument. (btw, passwords can be stored encrypted here) The maven-deploy-plugin has no option to pass them via commandline. However, I've seen hacks like:

<username>${internal.repo.username}</username> 

And now you can do -Dinternal.repo.username=someUser

like image 50
Robert Scholte Avatar answered Sep 20 '22 19:09

Robert Scholte


I'll lay out here the full solution, but basically Robert Scholte's solution works brilliant.

In your ~/.m2/settings.xml you should have the following

<settings>     <servers>         <server>             <id>${repo.id}</id>             <username>${repo.login}</username>             <password>${repo.pwd}</password>         </server>     </servers> </settings>   

and then you just

mvn -Drepo.id=myRepo -Drepo.login=someUser -Drepo.pwd=somePassword clean install

You can even use your environment variable (if you are doing that on the remote server/container, for example):

mvn -Drepo.id=$REPO_ID -Drepo.login=$REPO_LOGIN -Drepo.pwd=$REPO_PWD clean install

like image 29
Viacheslav Shalamov Avatar answered Sep 20 '22 19:09

Viacheslav Shalamov