Is there possibility for Maven to ignore settings.xml contained in .m2 folder?
I want it to use default repository, but my laptop has configured development environment for other repositories and I don't want to lose these settings. What's more, these repositories have priority over repos in my pom.xml and fail if they can't download artifact.
What are the options? Should I choose other settings.xml file or is there option to use none?
You don't have to have a settings.xml in the .m2 folder. If there is none Maven uses <Maven installation folder>/conf/settings.xml, which has everything commented out by default.
See also Settings Reference, Quick Overview:
There are two locations where a settings.xml file may live:
The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml
You can use custom settings files with the command line options:
-s,--settings
Alternate path for the user settings file
-gs, --global-settings
Alternate path for the global settings file
And, BTW, .m2 is not the Maven home. It's the folder for user-specific configuration and local repository. I corrected the question's title acordingly.
Related
I need do mention about Gradle to understand and find the same solution for Maven.
In Gradle exists the GRADLE_HOME and GRADLE_USER_HOME (repository) environment variables, for Maven the former through M2_HOME and about the repository I use the settings.xml file to define the <localRepository> location
For both Maven and Gradle I can define in peace the place about where is installed the software, for example other location than .m2 and .gradle to a secondary disk and even with customized directory names. Same goal about the repository location, both for a secondary disk (remember for Maven through the settings.xml file)
Note: therefore .gradle and .m2 are empty and not used.
In Gradle about the wrapper created, the gradle-wrapper.properties file has:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-#.#.#-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Then the final path is: GRADLE_USER_HOME/wrapper/dists
Therefore observe how GRADLE_USER_HOME (custom location - otherwise .gradle by default) is used to define the:
Local repository
Base path to install the downloaded Gradle through the wrapper
Goal: How accomplish the same behaviour for Maven? I mean, what should be the environment variable name (something like MAVEN_USER_HOME) for the local repository that Maven should recognize automatically? (not using the settings.xml file). It with the purpose to have any Maven wrapper installed according that environment variable name configured (custom location - otherwise .m2 by default) and of course defined the Local Repository too.
Therefore: I need the maven-wrapper.properties using something like MAVEN_USER_HOME (custom location - otherwise .m2 by default) according the developer/user in its machine.
For me, I am using spring boot boilerplate code that is generated from spring.io. Inside come with mvnw.cmd. By setting MAVEN_USER_HOME to a customized location, running mvnw.cmd will download the maven to that customized location.
Once done, I still need to manually go to that downloaded maven location to configure the settings.xml to point to a customized location for the maven libraries repo.
So at the moment, sadly, seem like the settings.xml is required to configure the repo, and MAVEN_USER_HOME environment variable has nothing to do with the repo.
Okay so I have been searching for the answer here in SE and came across this comment and several others like it
When Maven tries to build a project, it will look in your local repository (by default ~/.m2/repository but you can configure it by changing the value in your ~/.m2/settings.xml) to find any dependency, plugin or report defined in your pom.xml. If the adequate artifact is not found in your local repository, it will look in all external repositories configured, starting with the default one, http://repo1.maven.org.`
So my question is where is the settings.xml file suppose to reside?
I was told by the previous developers on the project that it is in the maven\conf\settings.xml which is where the only settings.xml file we have is located. This is contradictory to the above comment of .m2/settings.xml.
Please clarify where this file is to reside and if it makes a difference where it is at.
Both answers are correct.
Basic config file for maven is inside mvn/conf/settings and you could add some configuration (or override basic config) with your personal maven settings file located in ~.m2/settings.xml
settings.xml file may be found in 2 places:
The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml
If both files exists, their contents gets merged, with the user-specific settings.xml being dominant.
Ref : https://maven.apache.org/settings.html
I have one .m2 repository. I have 2 projects. JavaProject and HibernateProject. I want them to reference different .m2 repositories. How is this done?
You can't specify the local repository location in your POM file. If you were able to, it would break Maven: the whole point is to be able to distribute your POM file to other people and have the code just work. If the POM file contains a reference to ~seanmc/localrepos/hibernateproject then it's not going to work on my machine.
The place where you specify the local repository is in your settings.xml. Typically you have one global settings and one user settings. You can pass the -s flag to Maven to specify a settings file to use. So you could make a settings file for each project. Inside the settings file (reference) you'll want a <localRepository> tag with the path to the local Maven repository you want to use.
Be aware, though, that doing this is contrary to Maven's design. Probably, you have a bug in your architecture or your thinking.
I am new to maven and Jenkins, I am trying to build a maven 3 project.
I have maven in c drive and I moved the repository to d drive.
But when I configure a build in Jenkins, it is creating its own repository(I think so)
Now How to configure jenkis, so that it can use my repository in D drive.
Hope I made sense.
you need to adjust the settings.xml to point out which repository to use.
<localRepository>C:\\USER_LOCAL_DIR\.m2\m2repository</localRepository>
where USER_LOCAL_DIR is your user directory (e.g. Users\your_user_name).
Further more you should make sure which settings.xml the maven is using, if you dont have any specific user settings.xml the maven will start using the settings.xml which is at maven configuration directory, which will be M2_HOME/conf/settings.xml (M2_HOME being the Maven home directory). The hierarchy for settings.xml is first the user .m2 directory and if it could not find that, it will try to find the one in M2_HOME/conf/settings.xml.
Hope this helps.
You may need to check for settings.xml file under
..\maven-xx\conf\settings.xml file
C:\Users\Username.m2\settings.xml file
You may need to remember precedence in the order mentioned. In case if you need to point to a private maven repository consider to check both the files and in case if it's not pointing to intended location then update the settings file accordingly.
In windows, maven downloads everything in the C:\Documents And Settings\MyUser\.m2 folder (or C:\Users\MyUser\.m2). There exists some way to change the folder that it uses? Specially I want to set it to download anywhere BUT in the Documents And Settings/Users folder.
Look at your settings.xml in ${maven.home}/conf or, preferrably, ${user.home}/.m2/settings.xml (see this for details about the settings.xml). You can add (or uncomment) the following section:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
-->
<localRepository>/path/to/local/repo</localRepository>
as suggested by the commented out section already there by default. There, you should be able to change the path to achieve what you want.
For Eclipse IDE
If you are using your local maven as the Maven Installation in M2 plugin in Eclispe, editing the settings.xml wasn't enough for me. The plugin was still using the default {user.home}/.m2 as the repository location.
I had to go to : Windows > Preferences > Maven > User Settings and point to my local maven's settings.xml file in the Global Settings and/or User Settings input fields. Clicking apply will then start storing artifacts in the correct destination.