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

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.

Related

Connection timed out :connect error while downloading from Nexus in Maven

I want only single command to download from Nexus. I also tried using copy goal instead of get.
I am using the following command to download from Nexus:
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get -DremoteRepositories=url -Dartifact=groupId:ArtifactId:Version -Dhttps.protocols=TLSv1.2
But i am getting a timeout error and trying to download from central, not from my remote repository.
What changes do i need to do in settings.xml?
See here for instructions on setting up Maven to work with Nexus Repo: https://help.sonatype.com/display/NXRM3/Maven+Repositories#MavenRepositories-ConfiguringApacheMaven
check whether your network/firewall is blocking such request, there is a high possibility of firewall blocking access of maven repository location.
generic setting.xml looks like,
<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/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
Check MAVEN_HOME and M2_HOME in enviroment variable of setup of your local machine's maven home

Jenkins Maven job doesn't use localRepository from settings.xml

I have three Jenkins Maven jobs: one that builds and installs dependencies (JARs) and two that use those dependencies to bundle deployable WAR files.
I have configured all the three jobs to use a specific settings.xml file and, while not fully understanding the difference between the Settings file and Global Settings file (even after reading the ?, it's not clear), under Build I set both fields to the file path I wish to use, just in case:
/opt/maven/conf/settings.xml specifies:
<localRepository>/var/lib/maven/repo</localRepository>
however, the dependencies get downloaded in a different location: /var/lib/jenkins/maven-repositories/1 as /var/lib/jenkins is JENKINS_HOME.
The console output logs the following:
Executing Maven: -B -f /var/lib/code/src/pom.xml -Dmaven.repo.local=/var/lib/jenkins/maven-repositories/2 -s /opt/maven/conf/settings.xml -gs /opt/maven/conf/settings.xml clean install -P depBuild
which is confusing because maven.repo.local is different that what the file listed under -s and -gs says it should be.
Why does it not download and install dependencies in the local repo I specify in the settings.xml I tell it to use?
Here is the whole settings.xml:
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/var/lib/maven/repo</localRepository>
<servers>
<server>
<id>build.tomcat.all</id>
<username>buildman</username>
<password>mypass</password>
</server>
</servers>
<pluginGroups></pluginGroups>
<proxies></proxies>
<mirrors></mirrors>
<profiles></profiles>
</settings>
Try configuring it using the Config File Provider Plugin. After installing this plugin, you can create a config file in Manage Jenkins > Managed files > Add a new Config > Maven settings.xml.
It also starts you off with a template so you can just modify what you need. I just added the <localRepository> tag after the commented explanation about it.
Then in your Maven job, choose "provided settings.xml" and select the config file you just created.
Make sure you don't have any overriding options in MAVEN_OPTS and that "Use private Maven repository" is not checked.
PS: It doesn't look like you need to do this with "Global settings.xml" - you can leave that as "Use default". My limited understanding is that the global settings affects all users of the maven system, while the non-global one only affects the user that runs maven. I don't think it matters for most projects, but maybe if you have a special project where some shell execution happens under a different user, this could be important. (I'm just guessing.)

how to deploy artifacts (jar files) from POM.xml into jFrog repository?

I am new to this repository world.
I have a maven project i.e MavenExample from GitHub. and I have installed a jFrog artifactory in my machine.
My Aim is to deploy all the jar files listed in my pom.xml into jFrog artifactory instead of .m2 repo (default). This deployment of jar file must ocucur after mvn deploy command.
I have tried adding distributionManagement inside Pom.xml and changing the settings.xml inside maven/conf.
Can someone help... much appreciated.
Edited:
You can try editing "localRepository" in your settings.xml":
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!--
REST OF THE CODE
-->
</settings>
Go to your project directory and launch "mvn deploy".
The easiest way to obtain this information is from the "Set Me Up" section of Artifactory. Select the repository in the Artifacts tab, and in the top right corner, click "Set Me Up". Assuming you are using a local repository for deploying (remote will not work for deploying, only for resolving dependencies), it will show a section for deploying which will include the distribution management section. Place this in the pom.xml file of the parent project and this running the mvn deploy command from this directory will deploy to Artifactory.
A great way to see a working example of this is to view the "maven-example" section in JFrog's public Github page . You can see the parent project has 3 sub-modules (multi1, multi2, and multi3). Adding the distribution management section mentioned previously to the parent pom.xml file and then running mvn deploy from the parent project's root directory will deploy all the binaries to Artifactory.
If for some reason this is still not working, please provide your pom.xml for the parent, the name, package type, and if it is a local/remote/virtual of the repository. Additionally, please provide any output of the mvn deploy command (with the -X option) and anything you can find in the artifactory.log and request.log files ($ARTIFACTORY_HOME/logs/artifactory.log and request.log)

Could not calculate build plan: Plugin org.apache.maven.plugins:maven-jar-plugin:2.3.2 or one of its dependencies could not be resolved

I got the following error message when I tried to create a Maven project in eclipse. Many have posted about proxies in settings.xml file and also flush the .m2 folder forcing it to download a new one. None of this is working for me. I'm at work, with proxy settings active in the internet options.
The error message:
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved:
Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved:
Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
POM.XML:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blahhhhhhhhhhhhhhhhh</groupId>
<artifactId>HelloRESTEasy</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
settings.xml:
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxyserver.company.com</host>
<port>8080</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
Try cleaning the local .m2/repository/ folder manually using rm -rf and then re build the project. Worked for me after trying every possible other alternative(reinstalling eclipse, pointing to the correct maven version in eclipse, proxy settings etc)
I was able to solve the same problem with different solution.
The solution that worked for me was to Right click project "pom.xml" in eclipse and select "Maven Install".
I solved it now. However it only is solved in Netbeans. Not sure why eclipse still won't take the settings.xml that is changed. The solution is however to remove/comment the User/Password param in settings.xml
Before:
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxyserver.company.com</host>
<port>8080</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
After:
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>proxyserver.company.com</host>
<port>8080</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
Mainly this occurs during Eclipse upgrade.
I Solved using:
-> Right Click Project-> Maven->Update Project-> Select all (checkbox)
Old or out-dated, projects got refreshed with the updated jar files, and the required plugins. No more errors were visible.
For me, this problem occurs in Eclipse when the Maven installation is not well configured. By default the Maven installation is embedded in Eclipse. The .settings.xml file is set wherever the Eclipse installation points.
In my case this file was not auto-generated. I choose my own Maven installation - an external one. But if you don't explicitly choose where settings.xml is then Eclipse tries to get this file from the path set in the embedded installation. If the file is not autogenerated you have to choose the correct location.
Go to windows/preferences/Maven/Installation/user settings and choose the correct location of your settings.xml.
I also faced the above error. I used Eclipse.
After followed the below solution, it works fine for me.
Solution is,
Right click project "pom.xml" in eclipse and select Maven Install.
Right click on the project -> Maven -> Update Project.
Refresh
Right click project "pom.xml" in eclipse and select Maven Install.
Right click on the Project -> Maven -> Update Project.
Then Refresh.
I have had this issue and I resolved it by following the next step:
1- Close Eclipse.
2- Go to user directory and delete the .m2 directory.
3- Open Elipse.
4- Right click on the project -> Run as -> maven install
I have had this issue, and removing the .m2/repository/ has not solved it in my case. Seems that eclipse is unable to download the maven-plugin or dependency needed. Therefore you need to install it yourself.
I have finally solved it downloading both jar and pom files from the Maven Repository and installing it using the command (better than copying to the folder directly):
mvn install:install-file -Dfile=<path-to-file> -DpomFile=<path-to-pomfile>
(In my case: mvn install:install-file -Dfile=maven-war-plugin-2.2.pom -DpomFile=maven-war-plugin-2.2.pom)
In my case the error was: CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 ....
With eclipse luna from console in the pom.xml folder
mvn clean
mvn install
With Juno I had to had this to my pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
And then
mvn install
And then from eclipse right click>maven>update project
* Once the plugin is donwloaded you can remove the plugin from your pom.xml
Jotting down some steps which help:
Writing answer from eclipse perspective as base logic will remain the same whether done by Intellij or command line
Rt click your project -> Maven -> Update project -> Select Force update -> Click OK
Under properties tag , add :
> <maven.compiler.source>1.8</maven.compiler.source>
> <maven.compiler.target>1.8</maven.compiler.target>
In some instance , you will start seeing error as we tried force update , saying , failure to transfer X dependency from Y path , resolutions will not be reattempted , bla bla bla
**In such case quickly fix it by cd to .m2/repository folder and run following command :
for /r %i in (*.lastUpdated) do del %i**
I also had the same problem. I used next way:
1.Added settings.xml file (~/.m2/settings.xml) with next content
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>qq-proxya</host>
<port>8080</port>
<username>user</username>
<password>passw</password>
<nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
</proxy>
</proxies>
3. Using cmd go to folder with my project and wrote mvn clean and after that mvn install !
After that updated project in the Eclipse(Alt + F5) or right click on project -> Maven -> Update project
P.S. after that, when I add new dependency to my project I have to compile project using cmd(mvn compile). Because if I do it using eclipse plugin, I get error connecting with proxy connection.
I had this error, I follwed below three steps to solve,
1). check proxy settings in settings.xml refer,
2). .m2 diretory to release cached files causing problems
3) Point your eclipse to correct JDK installation.
Refer No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? to know how
I also faced same problem... I follow the following steps...u can try it
1. Right click on maven project
2. Take cursor in Maven
3. Click on Update Maven project or (alt+F5).
it will take some time then most probably problem will solved..
There could be multiple reasons, i fixed with following steps:
delete .m2 folder and re launch eclipse. (Find m2 folder in
windows: c:\Users\Your_User_Name\ .m2
or to search in Mac : ~/.m2
make sure settings.xml is configured as #JustinBieber mentioned.
provide settings.xml path in eclipse (windows->preferences->maven->user settings) User Settings must locate settings.xml file.
save changes and relaunch the eclipse..!! it should work.
Excellent i got solution:
Just clearing (.m2) complete folder and starting a new maven project problem solved for me.
Note:: .m2 folder located in os installed disk only.
If you want the exact location, check in Eclipse:
Eclipse-->window-->preferences-->maven-->user settings
There local repository path is for .m2
Delete entire .m2 folder and restart your eclipse.
I had same issue while creating new spring project in eclipse using Maven.
The main reason for this issue is that the proxy settings was not there.
I used the following approach to reslove it:
1) create settings.xml with the below content
<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/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>Your proxy</host>
<port>Your port</port>
</proxy>
</proxies>
<profiles/>
<activeProfiles/>
</settings>
2) Save the settings.xml file under local C:\Users\<<your user account>>\.m2
3) Then Right click project pom.XML in eclipse and select "Update Project". It always give precedence to settings.XML
I have summarised what I did for my issue.
1) Delete .m2 folder.
2) Change the apache-maven-3.5.4\conf\settings.xml as follow
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>proxyserver.company.com</host> --> Please change it according to your proxy
<port>8080</port> -->Please change it accordingly
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
3) Try again in cmd. It will work.
4) For eclipse, delete the existing maven project and go to
window ->prefernces -> maven -> user settings -> browse -> configure this path apache-maven-3.5.4\conf\settings.xml
5) Delete .m2 folder.
6) Restart the eclipse and try creating new maven project.
These steps worked for me.
Maybe your network is slow, so that jar isn't downloaded completely.
There are two methods:
a. find your .m2 folder, you can find some path like this 'org/apache/maven/plugins/maven-resources-plugin', you need only delete this foldler 'maven-resources-plugin', because others are downloaded well.
Then maven build your project.
If other problem occures, repeat this process again.
b. you can change a more quick maven source.
Firstly, you should find maven's settings file(window ->prefernces -> maven -> user settings). If it is empty, you can create a new one (any path, for example, .m2/settings).
Secondly, add sth like this (From https://blog.csdn.net/liangyihuai/article/details/57406870). This example uses aliyun's maven.
<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">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
Thirdly, maven build again. (before this, you should delete your .m2 folder's files)
Force update works for me.
Select the force update option as per image in update maven project.
run:
mvn -U dependency:go-offline
It works for me.

Maven - 2.2.1 -------Access denied error

Access denied error coming while building using the maven 2.2.1 build tool
It might be about folder that contains your source code permissions or maven repo authentication.
First look at the folder permissions. If this does not solve your problem you can try to add auth information of the repo that you try to download from, into your settings file;(Settings file is settings.xml in conf folder in your maven installation folder or under .m2 file)
<settings>
<servers>
<server>
<id>myrepo</id>
<username>myusername</username>
<password>password</password>
</server>
</servers>
</settings>
You can see this part in your default maven settings file as commented. You can read comments as a simple documentation of settings file.
This happens when multiple processes are trying to access the same file simultaneously.
Most likely one process in reading this file and another is trying to write it at the same time when your IDE where its trying to compile the project while you are running maven from the command line.

Resources