mvn release:prepare doesn't work using maven 3 - maven

My JAVA_HOME is properly set up to /usr/local/java/jdk1.7.0_01
$echo $JAVA_HOME
/usr/local/java/jdk1.7.0_01
$sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
* 2 /usr/local/java/jdk1.7.0_01/bin/java 1 manual mode
3 /usr/local/java/jre1.7.0_01/bin/java 1 manual mode
I am using mvn release:prepare plugin to produce the git tag and flip project's version in the pom.xml. It works perfect if I use maven 2.2.1 When I use maven 3.0.4, I get:
[INFO] Error: JAVA_HOME is not defined correctly.
[INFO] We cannot execute /usr/local/java/jdk1.7.0_01/bin/java/bin/java
I guess there might be a bug in maven 3, when it runs, it tries to append /bin/java twice to my JAVA_HOME.

Try using the standard Oracle/Sun JDK, if that is an option at all. I have hit this myself before on Debian/Ubuntu. I never had the patience to figure out what was wrong with the OpenJDK, but it doesn't cope well with Maven. Or... at least... such was my observation.

JAVA_HOME must point to jre, then set :
export JAVA_HOME=/usr/local/java/jdk1.7.0_01/jre

Search JAVA_HOME in your mvn command file (use which mvn to find it).
Mine does handle the JAVA_HOME if not already defined.
So perhaps you can get around it by unset JAVA_HOME

remove the file in old maven home and it will change to new one.
mv /usr/local/Cellar/maven/3.8.1/libexec /usr/local/Cellar/maven_bak
before that, you need to export your jdk and maven firstly. and how to do this, you can see following link.
https://stackoverflow.com/a/67715235/11679986

Related

Error while run the maven framework through command prompt but it's running fine with eclipse

I faced the issue with the surefire plugin "2.19.1" as below. I have tried with the version 2.19.1,2.12.4,3.0.0-M1
You're maven seems to be corrupt. Assuming you're on a windows machine:
1) set M2_HOME environment variable to the folder where maven is. (if in doubt download it and put it somewhere, it's just a java program.
2) set JAVA_HOME environment variable to the folder where your java is.
3) add %JAVA_HOME%/bin:%M2_HOME%/bin to the start of your PATH environment variable.
4) Make sure your ~/.m2/ folder has a settings.xml in it, you can use the one from the maven download to start. (you may need to add the proxy details)
5) Test with
mvn -version
6) You can clear your local repository by deleting files in ~/.m2/repository if you've not done much and have a reasonable network just blow the whole thing away.

-Dmaven.multiModuleProjectDirectory system property is not set in JDeveloper 12.1.3 and external maven

In JDeveloper 12.1.3 get 'suddenly' follwing error when running any maven goal on a random Java application. I mean suddenly, because i use JDeveloper infrequently for making modifications to Java classes and do not have full control over my Development environment. (Managed by admins).
Most important env variables are;
M2 = %M2_HOME%\bin
M2_HOME = D:\Tools\apache-maven-3.3.9
MAVEN_HOME = D:\Tools\apache-maven-3.3.9
MAVEN_OPTS = -Xms256m -Xmx512m -Dmaven.multiModuleProjectDirectory=%MAVEN_HOME%
I also tried enclose %MAVEN_HOME% in double quotes.
Maven preferences in JDeveloper are
Maven Version, external version: D:\Tools\apache-maven-3.3.9
User settings: D:\Tools\apache-maven-3.3.9\conf\settings.xml
Additional settings: -X -DdownloadSources=true -DdownloadJavadocs=true -P deploy-to-local-server -Dmaven.multiModuleProjectDirectory=D:\Tools\apache-maven-3.3.9
Local Repository: D:\Tools\Apache\maven3_repository
Index Directory: D:\Tools\Apache\maven3_index
All settings seems to be ok. When running mvn from the commandline, e.g. mvn test --settings D:\Tools\apache-maven-3.3.3\conf\settings.xml the build completes successfully.
Als tried to set the Java property in the jdev.conf AddVMOption -Dmaven.multiModuleProjectDirectory="%MAVEN_HOME%"
If the mvn goal test is chosen in JDeveloper it executes the command;
D:\Oracle\Java\jdk1.7.0_45\bin\javaw.exe -classpath D:\Tools\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar;D:\Tools\apache-maven-3.3.9\lib\wagon-provider-api-2.10.jar;D:\Tools\apache-maven-3.3.9\lib\wagon-http-shared-2.10.jar;D:\Tools\apache-maven-3.3.9\lib\wagon-http-2.10-shaded.jar;D:\Tools\apache-maven-3.3.9\lib\wagon-file-2.10.jar;D:\Tools\apache-maven-3.3.9\lib\slf4j-simple-1.7.5.jar;D:\Tools\apache-maven-3.3.9\lib\slf4j-api-1.7.5.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-utils-3.0.22.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-sec-dispatcher-1.3.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-interpolation-1.21.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-component-annotations-1.6.jar;D:\Tools\apache-maven-3.3.9\lib\plexus-cipher-1.7.jar;D:\Tools\apache-maven-3.3.9\lib\org.eclipse.sisu.plexus-0.3.2.jar;D:\Tools\apache-maven-3.3.9\lib\org.eclipse.sisu.inject-0.3.2.jar;D:\Tools\apache-maven-3.3.9\lib\maven-settings-builder-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-settings-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-repository-metadata-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-plugin-api-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-model-builder-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-model-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-embedder-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-core-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-compat-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-builder-support-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-artifact-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\maven-aether-provider-3.3.9.jar;D:\Tools\apache-maven-3.3.9\lib\jsr250-api-1.0.jar;D:\Tools\apache-maven-3.3.9\lib\jsoup-1.7.2.jar;D:\Tools\apache-maven-3.3.9\lib\javax.inject-1.jar;D:\Tools\apache-maven-3.3.9\lib\guice-4.0-no_aop.jar;D:\Tools\apache-maven-3.3.9\lib\guava-18.0.jar;D:\Tools\apache-maven-3.3.9\lib\commons-lang3-3.4.jar;D:\Tools\apache-maven-3.3.9\lib\commons-lang-2.6.jar;D:\Tools\apache-maven-3.3.9\lib\commons-io-2.2.jar;D:\Tools\apache-maven-3.3.9\lib\commons-cli-1.2.jar;D:\Tools\apache-maven-3.3.9\lib\cdi-api-1.0.jar;D:\Tools\apache-maven-3.3.9\lib\aopalliance-1.0.jar;D:\Tools\apache-maven-3.3.9\lib\aether-util-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-transport-wagon-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-spi-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-impl-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-connector-basic-1.0.2.v20150114.jar;D:\Tools\apache-maven-3.3.9\lib\aether-api-1.0.2.v20150114.jar; -Dclassworlds.conf=D:\Tools\apache-maven-3.3.9\bin\m2.conf -Dmaven.home=D:\Tools\apache-maven-3.3.9 org.codehaus.classworlds.Launcher -X -DdownloadSources=true -DdownloadJavadocs=true -P deploy-to-local-server -Dmaven.multiModuleProjectDirectory=D:\Tools\apache-maven-3.3.9 --settings D:\Tools\apache-maven-3.3.9\conf\settings.xml --file C:\Projecten\project\A\B\pom.xml clean -Denv.ORACLE_HOME=D:\Oracle\Middleware_JDev12.1.3
When executing this command on the commandline it completes, but does not seem to execute to goal. If javaw is replace with java it shows the error -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match. again. As can be seen in de command extract above, the system property is set.
Any other suggestions ?
Downgrading Maven to 3.1.1 resolved the issue. For now this is a solution for me.

Apache Maven is not configured properly into System vairable

I have latest version of Apache Maven 3.3.9 residing in my drive downloaded from here. I need it for configuring Appium tool to perform automated testing of Android applications. I have Maven plugin already configured with my Eclipse IDE. I went through few articles and got to know that I have to configure Maven into system variables as well. I set system variables, path for it as below.
M2HOME = C:\Program Files (x86)\Apache\apache-maven-3.3.9
M2 = %M2HOME%\bin
path = C:\Program Files\Java\jdk1.8.0_31\bin;%M2%
I tried running mvn , mvn -version from cmd prompt to check successful configuration of Maven but it gave me nothing. I tried navigating to the bin folder and re run the command but still the result is same. I even changed my path variable to have absolute path of Apache Maven i.e path = C:\Program Files (x86)\Apache\apache-maven-3.3.9\bin
To be further sure I copied the Apache Maven to a different folder just because it had spaces in between Program Files and Program Files (x86) but still the command prompt is as below:
I had followed above steps referring various articles in google. I'm not getting if I have committed any unseen mistake.
P.S: I have even tried above commands with cmd running as an administrator
Try mvn --version (with two dashes). mvn -v should also work. If Maven is not being executed at all, I suggest you try mvn.bat.
Some Command Prompt configurations will refuse to run .bat-files without the extension unless you explicitly tell them to.
It's probably a good idea to run where mvn in your Command Prompt as well. You should get this:
<YOUR_MAVEN_HOME>\bin\mvn
<YOUR_MAVEN_HOME>\bin\mvn.bat
<YOUR_MAVEN_HOME>\bin\mvn.cmd
if everything it set up correctly.
You should define M2_HOME variable. (Not M2HOME). Make sure it looks like this:
You said that you copied your maven to the location without spaces. That's a good idea. But it looks like your Path system variable points to the old location of maven. Make sure to change it. (What is the current location of maven?)
BTW mvn -version works as well as mvn --version

Error: M2_HOME is set to an invalid directory

I got this error
Error: M2_HOME is set to an invalid directory.
M2_HOME = "C:/Users/joanet/.m2/repository"
Please set the M2_HOME variable in your environment to match the
location of the Maven installation
but C:/Users/joanet/.m2/repository is a valid directory !
Yes, your folder is valid, but this is not the folder you want to point to.
I think it should point actually where the error messages says to you, to your maven installation folder (something like this)
C:\development\maven\apache-maven-3.1.0
You are currently pointing to your local repository, something which is usually configured in the settings.xml of maven (in the conf folder of the previous url route).
Such issue appears also, if you have 2 or more mavens installed. Try to delete old versions to have only latest.
Check the System Variable M2_HOME and PATH values set in different maven installation locations.
If your java version is 8
you can remove "MAVEN_OPTS : -Xms256m - XMX512m" environmental variable and check "mvn -v".
because java 8 does not support for the above config.
This happened to me when I tried to upgrade to new Maven version.
Below are the steps you should follow when setting up Maven on Windows. If something is missing, the above error will trigger (most probably the 2nd or 3rd step may be missing for mentioned error).
Step 1:
First, download(Apache Maven download link:
https://maven.apache.org) and extract it to C:\Program Files
Step 2:
Go to Environment Variables and Define below varibles in System variables
M2_HOME - C:\Program Files\apache-maven-3.3.9 MAVEN_HOME -
C:\Program Files\apache-maven-3.3.9
Step 3:
Make sure to add the maven bin file to Path varible in System variable
C:\Program Files\apache-maven-3.3.9\bin
Step 4:
Once you are done with configurations, make sure to restart the project.
Step 5:
Check whether the Maven is configured successfully using below command
mvn -version

Maven ignores settings.xml file

I have added proxy configuration in settigns.xml file, but it is not used by Maven, i confirmed this by making the settings.xml file invalid. I ran the maven install command to update settings and global-settings to point to the correct file, still no luck. I am using maven3.0.4.
Try running Maven with the -X option. It should print as part of the debug output which settings file is being used.
Since you already tried it with an invalid file, I bet that something is wrong with the location of your file.
It's almost to stupid to tell, but it might save some time for somebody else: If you're using a new computer, make sure file extensions are displayed. Otherwise your "settings.xml" file probably is a "settings.xml.txt" file in fact...
Make sure it is in the right directory (HOME/.m2/settings.xml)
You can find the relevant paths and a proxy example here: Maven proxy settings not working
And of course the reference is always useful: https://maven.apache.org/settings.html
have you tried with these options: from the command line to specify the settings file?
mvn -o –Dmaven.repo.local=$HOME/.my_m2path/repository clean install --settings $HOME/.my_m2path/settings.xml Dcheckstyle.skip=true –DskipTests
Some options that might not be necessary
-o is for offline (unless you have all your repos in your m2, its suggested to skip this option)
skip tests is for skipping tests while building
–Dmaven.repo.local - repo path - if you are having own repo path, then use this option
--settings $HOME/.my_m2path/settings.xml (remember there is space between settings and the path)
Since there is no accepted answer, and I encountered that problem today and other answers proved unhlepful as the file path was correct:
The solution is to restart your computer. No, seriously. After restart maven is guaranteed to read settings.xml file again and use whatever changes you made.
For those using Linux
In the Ubuntu package repository (and probably other disto's too), there are two maven packages: maven and maven2. For some reason, I had maven2 installed, which seems to ignore settings.xml in ~/.m2.
As a solution, I removed it using
sudo apt-get purge maven2
and installed the other one with
sudo apt-get install maven
What's going on?
I couldn't find a reliable source, but apparently, maven2 is an older version (2.x), as the latest maven has version 3.x and is served with maven.
Please make sure you are using the settings.xml which you modified.
for example: your using IDE's embedded maven which using different settings.xml in you operation system.
You can set the path of settings file in Eclipse* as :
In the menubar goto Window -> Preferences
In Preferences Dialog, Goto Maven Section(On the left) and Expand it.
Click on UserSettings.
Add the path of settings file using Browse. The default for most users will be (C:\Users\.m2\settings.xml). It will be shown in grey but you need to actually enter the location.
Click on Update Settings !
You can also enable debug logs and stack traces for debugging by clicking on the Maven Section in the Preferences dialog and Checking the box against the label "Debug Output".
P.S. I am currently using Eclipse(Neon) on Windows 10 x64.
I have also been facing the same issue. I removed the file and folder, but still maven was still picking the settings.
For me, restarting the system solved the issue.
What I found was that even if I set my own maven setting file using the --settings or -s command such as:
mvn -s $MAVEN_HOME/libexec/conf/my-settings.xml clean
Maven was still reading the default global setting.xml
Two ways that one can slove this:
Rename the setting.xml to something like setting.xml.bak in the $MAVEN_HOME/conf dicrectory.
The preferred approach add global to the command -gs hence the final command becomes:
mvn -gs $MAVEN_HOME/libexec/conf/my-settings.xml clean

Resources