jenkins maven repository configuration - maven

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.

Related

How define for Maven's Environment Variable to define Local Repository and Wrapper download location?

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.

Which folder does the Maven settings.xml file belong in?

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

Point maven settings file to refer from \.m3\settings.xml instead of \.m2\settings.xml

I am upgrading from maven 2 to maven 3. I have changed the maven home from M2_HOME to M3_HOME, created .m3 folder put the settings.xml inside it. Removed the .m2 folder also.
I see in the maven 3 global settings.xml, the default location of settings.xml is .m2\settings.xml. I could force maven to read the settings.xml from inside .m3 folder by supplying
mvn clean install -Dmaven.repo.local=C:/Users/tabeme/.m3/repository --settings C:\Users\tabeme\.m3\settings.xml
But I dont want to do this every time I build. Is there a way I can permanently make maven to read settings.xml from .m3 folder?
Maven 3 is a drop in replacement for maven 2.
It uses M2_HOME and .m2 folders as normal.
You should only change settings if you for some reason want to run multiple maven instances.

How to specify different local maven repositories for different projects in their pom files?

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.

Does maven maintain any setting cache?

I comment out my local repository section im my pom.xml, but when I ran mvn eclipse: eclipse, it still try to download plugin from local repository. I also check the pom.xml it depends on and make sure to comment out them either, but this problem still occurs.
I think I might neglect some setting?
You may have a settings.xml in the default maven repository location .m2. If you are running maven inside eclipse, check your maven configuration inside Eclipse preferences, there you should find the location of the settings.xml file.

Resources