4

I have Maven 3.5.4 and it's probably not the latest, because I'm having problem when I'm trying to build "mvn clean install" my project.

So my question is how do I update Maven to the latest version?

Nowhere in the internet I found an answer to this simple question!

And why in IDE (IntelliJ Idea) I can build my project, but in CMD I can't? Do they have different Maven versions?

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
Arzybek
  • 547
  • 2
  • 6
  • 27
  • Your IDE might not use Maven at all, use an embedded version of Maven or another installation. Updating Maven would just mean you install the newer version and use it to run your build. To support a simple `mvn install` without a specific path to `mvn` you'd need to put the new installation's bin directory onto `PATH` (assuming you're running on Windows) and before the old installation (or remove that). However, the Maven version might not be the reason for your problems at all. If could be something else but we lack the details to tell. – Thomas Aug 27 '21 at 11:48
  • It is recommended to use the latest version that you can easily find by googling "maven". Nevertheless, your problem, whatever it is, is probably not related to the maven version. – J Fabian Meier Aug 27 '21 at 12:31

4 Answers4

2

First question

You should manually download the latest version fron Official web site and use it as a standalone application.

Second question

IntelliJ uses its own maven release.

Joe
  • 29,416
  • 12
  • 68
  • 88
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • 1
    Use the general link to the download page: https://maven.apache.org/download.cgi without preselecting a mirror... – khmarbaise Aug 27 '21 at 12:39
2

If you are using the maven wrapper you can update the version with (from the root of your project directory):

./mvnw -N wrapper:wrapper -Dmaven=3.8.7

(3.8.7 is the desired version).

Complete example:

$ ./mvnw --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
...
$ ./mvnw -N wrapper:wrapper -Dmaven=3.8.7
...
$ ./mvnw --version                                                                                                                                          
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)

This will update .mvn/wrapper/maven-wrapper.properties to use the correct version and download it to ~/.m2/wrapper/dists/.

And SKDMAN! is also highly recommended, see answer @marvi

rmuller
  • 12,062
  • 4
  • 64
  • 92
1

It depends on your operating system. I use https://sdkman.io/ on Linux and MacOS. On Windows you could use WSL and sdkman or https://community.chocolatey.org.

Yes, IntelliJ has an internal Maven bundled and it might have a different version number than what you have installed in the operating system.

You can also download a binary package from maven.apache.org and just unpack it somewhere. Then you have to set your PATH system variable to find mvn in your shell.

marvi
  • 186
  • 2
  • 7
-2

You can install a different version of Maven at: https://maven.apache.org/download.cgi

It also has previous versions history here: https://maven.apache.org/docs/history.html

You then point the M2_HOME environment variable to this new version in order to use it in the command line. You will need to make sure that you use the M2_HOME environment variable and ensure that the M2_HOME/bin is in your PATH environment variable.

Raza
  • 30
  • 3
  • Don't set `MAVEN_HOME`; see https://stackoverflow.com/questions/17136324/what-is-the-difference-between-m2-home-and-maven-home/19765881 for more details. – Joe Aug 27 '21 at 11:59
  • 1
    Do not set `M2_HOME` as well because it's not needed not helpful. Only PATH entry is needed. – khmarbaise Aug 27 '21 at 12:38
  • Most people would have used the M2_HOME environment variable. I might have added that its not necessary but assumed that OP has this already set. – Raza Aug 27 '21 at 12:47