Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will intellij idea "mvn install" automatically when make the project?

I'd like to know what will Intellij IDEA do with my Maven project when I click "build the project"?
How will Intellij build the project with Maven?

like image 238
guo Avatar asked Nov 01 '16 11:11

guo


People also ask

Is Maven automatically installed with IntelliJ?

If you want to use a custom Maven version that is not bundled with IntelliJ IDEA, you need to install it locally.

What happens when we do mvn install?

On a mvn install , it frames a dependency tree based on the project configuration pom. xml on all the sub projects under the super pom. xml (the root POM) and downloads/compiles all the needed components in a directory called . m2 under the user's folder.

Does Maven install also package?

mvn package command will compile source code and also package it as a jar or war as per pom file and put it into the target folder(by default). mvn install command will compile and package, but it will also put the package in your local repository.


2 Answers

Intellij IDEA will not automatically do a make install when you do a Build Project. In order to do that, proceed as follows:

enter image description here

Under Maven Projects tab (usually on the right hand side), select the goals you want Intellij to run after a Build -> Make Project and then right click and select the trigger (for instance in the above snapshot, the trigger was chosen as 'Execute After Make'. You can choose whatever you wish).

After doing this a Build -> Make Project will run a mvn clean install as well.

like image 58
Ashutosh Jindal Avatar answered Oct 28 '22 10:10

Ashutosh Jindal


IntelliJ's build system refers to the Maven ecosystem for some hints, but at the end of the day it is a separate build system.

In IntellIJ, you have a Project, with many Modules. These are both IntelliJ concepts.

An IntelliJ Module has a responsibility to understand what are its dependencies and libraries. This can be done purely with IntelliJ semantic, or IntelliJ can allow some other build system to declare the dependencies and libraries. That is to say: the IntelliJ Module can be based on a Maven pom.xml or Gradle's build.gradle.

When you click "Make" on an IntelliJ Java Module: IntelliJ will check which libraries your Module asks for, and also resolve the dependencies of your Module to work out which libraries its dependent Modules ask for.

Once the libraries are known: IntelliJ will invoke Javac or the Eclipse Compiler (whichever you've configured as your Java compiler) with all those libraries on the classpath. And it will output a jar, not a Maven artefact.

IntelliJ Make will not run a mvn compile or similar (unless you configure it to explicitly, as per @Ashutosh Jindal's answer.

Why would IntelliJ use its own, separate build system, when you've provided an authoritative definition for how you'd like to build your project? I can imagine various reasons:

  • Maven generally just outputs an artefact (sources and binary jars, and a pom.xml), whereas IntelliJ needs additional semantic and indexes to provide all its IDE intelligence. It makes sense to perform the indexing process alongside the compile, since: if you do the compile incrementally, you can understand incrementally which indexes are dirtied also.
  • The IDE benefits from being involved in the compilation process. For example: IntelliJ can do "continue on error" builds using the Eclipse compiler. Additionally, the Eclipse compiler can be used to compile only those files which have changed (IDEs watch you as you code, so they know very well which files are dirtied). I have heard that Maven does incremental compile, but I don't know how its performance compares.
  • In order to support a variety of build systems (Ant, Maven, Gradle): the easiest engineering choice for IntelliJ is to rely on the minimum possible amount of domain-specific semantic, and use that to inform one IntelliJ-specific build system. This allows them to re-use a large amount of code, and have few domain-specific differences.
like image 28
Birchlabs Avatar answered Oct 28 '22 08:10

Birchlabs