Maven <LocalRepository> tag in pom.xml - maven

By default Maven downloads all the dependencies to ${user.home}/.m2/repository/ dirctory.
I read about the tag LocalRepository which allows us to change the default path. I tried adding this tag add different locations in pom.xml file. But I could not find its exact location in the pom.xml file.
Do I need to put it in settings.xml or pom.xml?
can you please help me to add this tag to correct position in xml file.
<settings>
<localRepository>
D:\Ravindra\Projects\MavenSpringJar\
</localRepository>
</settings>
Is it inside <project>,<dependencies>,<dependency> tag?
Thanks.

The localRepository tag is only allowed within the setttings.xml file but not in the pom.xml file.

Related

How to move maven directory ".m2" from my home directory after installing IntelliJ

I've just installed IntelliJ 15 on Ubuntu and wanted to update maven repository indices, I am having disk space errors because my home folder is on a limited size partition.
I am totally lost trying to move ~/.m2 to somewhere else. I've tried IntelliJ settings and changed paths and maven settings but didn't work and most of the time they return to the home folder after restarting IntelliJ.
I wanted to add that I didn't install maven (using apt-get install maven). Would this help or give more control?
You can modify the location of the Maven local repository by modifying the Maven settings. From Configuring your Local Repository:
The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/.
<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
Note: The local repository must be an absolute path.
Since you are using the Maven installation that is shipped with IntelliJ and not your own Maven version, you can create a Maven user settings:
Create a file settings.xml under ${user.home}/.m2/
Have the following content in it:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/path/to/local/repo</localRepository>
</settings>
Maven will read this file and use the specified local repository.
Another alternative I found is also by eclipse itself.
Create the setting.xml file in my D:\TAAS\settings.xml directory as follows:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:\TAAS\.m2\repository</localRepository>
</settings>
Then I configured it by the eclipse itself according to the following figure.
This is an option for maven embedded versions.

How to access properties from settings.xml to spring.xml and pom.xml to spring.xml

I am new to maven spring.I have two questions.
How to access property set in settings.xml to spring.xml
How to accesss property set in pom.xml to spring.xml
Thank you.
You want to filter your resources, a maven term that means replacing property placehoders in one file with values from your maven pom. To do this you use the resources plugin in your build configuration.

Version in jar name

When I import mvn project into Intellij the jar file it generates doesn't include version. But mvn generated jar has name-version.jar format. So I end up with two jar files one with version and another without one. I can of course, change module name in Intellij settings to include version. But that will be reset whenever I change pom file.
Maybe somebody else had a better idea?
The jar name that Maven generates on disk is controlled by /project/build/finalName so if you edit your pom.xml to look like
<project>
...
<build>
...
<finalName>${artifactId}</finalName>
...
</build>
...
</project>
and then Maven will be generating the jar file without the version.
Note
finalName only controls the name of the file on disk. Once that file is transferred into the local repository cache or a remote repository it will be renamed to match the repository layout (i.e. ${artifactId}-${version}.${type} or ${artifactId}-${version}-${classifier}.${type} for artifacts with a classifier). You cannot change the format used by the repository.
I add the above note because the first thing everyone seems to want to do upon learning about the finalName parameter is try and change the name in the repository.
use version tag of the maven
<version>0.0.1-SNAPSHOT</version>
do not let intellij to create jar files without version tag.

Changing the name of the generated war file from command line with maven

According to the maven war plugin documentation I should be able to set the name of the generated war file with the parameter warName. Is it not possible to do this from the command line with mvn -DwarName=mySpecificName package? When I run maven like this the war file still gets the default name.
My webapp project is part of a multi module project and I only want to change the final name of the war file, not any other projects generated artifact.
I am using maven 3.0.4 and version 2.3 of the war plugin.
You can achieve the same effect by maven property.
1) Define a property via
<properties>
<my.warName>xxx</my.warName>
</properties>
You can overwrite the default value by "-Dmy.warName=commandlineWarName"
2) Redefine the war name
<build>
<finalName>${my.warName}</finalName>
<!-- ... -->
</build>
After looking at the code of the war plugin I realize that it is not possible to set the warName parameter from command line. I assumed that all parameters were possible to set from the command line. This assumption was incorrect.

Maven plugin prefix resolution doesn't seem to work as expected

I've created a MOJO for a specific application need. I've followed maven's guidelines in naming the plugin so that I didn't have to mention the full
mvn groupId:artifactId:version:goal
for executing my plugin(I've named it to match the format ${prefix}-maven-plugin).
I've even included the 'goalPrefix' property in the plugin POM's configuration section. Here's a sniff of what I did to my plugin's POM:
<configuration>
<goalPrefix>${prefix}</goalPrefix>
</configuration>
But I'm still unable to execute my plugin just using mvn ${prefix}:goal since it complains it can't find the plugin in any repository. I've still had to use mvn groupId:artifactId:version:goal Any idea why?
By default, Maven does only recognize plugins with the group IDs org.apache.maven.plugins and org.codehaus.mojo. If your plugin has a different group ID (which should be the case), you need to add this group ID as plugin group to your Maven settings.xml file:
<settings>
...
<pluginGroups>
<pluginGroup>the.groupid.of.my.plugin</pluginGroup>
</pluginGroups>
...
</settings>
Take a look at the Maven Settings Reference for further details.

Resources