Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add maven repositories in the command line?

I'm aware I can add maven repositories for fetching dependencies in ~/.m2/settings.xml. But is it possible to add a repository using command line, something like:

mvn install -Dmaven.repository=http://example.com/maven2 

The reason I want to do this is because I'm using a continuous integration tool where I have full control over the command line options it uses to call maven, but managing the settings.xml for the user that runs the integration tool is a bit of a hassle.

like image 426
Sindri Traustason Avatar asked Sep 16 '08 10:09

Sindri Traustason


People also ask

Where is Maven repository located in CMD?

For windows users Usually it's in: C:\Users\USER_NAME\. m2\repository . However the mvn help:effective-settings command will surely show the local path in response xml.

Can we add repository in POM xml?

Putting non-standard repositories in the pom. xml file (which gets checked into source control) means every developer can build. But YES, your authentication for a repository server should be in your private settings. xml file.

How do I host a Maven repository?

The best solution I've been able to find consists of these steps: Create a branch called mvn-repo to host your maven artifacts. Use the github site-maven-plugin to push your artifacts to github. Configure maven to use your remote mvn-repo as a maven repository.


2 Answers

You can do this but you're probably better off doing it in the POM as others have said.

On the command line you can specify a property for the local repository, and another repository for the remote repositories. The remote repository will have all default settings though

The example below specifies two remote repositories and a custom local repository.

mvn package -Dmaven.repo.remote=http://www.ibiblio.org/maven/,http://myrepo    -Dmaven.repo.local="c:\test\repo" 
like image 62
Rich Seller Avatar answered Sep 28 '22 05:09

Rich Seller


One of the goals for Maven't Project Object Model (POM) is to capture all information needed to reliably reproduce an artifact, thus passing settings impacting the artifact creation is strongly discouraged.

To achieve your goal, you can check in your user-level settings.xml file with each project and use the -s (or --settings) option to pass it to the build.

like image 26
2 revs Avatar answered Sep 28 '22 05:09

2 revs