What is the difference between adding dependencies via IntelliJ IDEA (when I download the library to my computer and add it to the project via Project Structure -> Libraries) and via Maven (when I specify group id, artifact id and version in pom.xml)? And which of these ways is better?
CodePudding user response:
Using maven is better when we collaborate with others, so we keep the version in pom file and the build will be stable.
When we use IDE, we'll download the latest version of the dependency and it may lead to build issues.
I suggest to use Maven, or use Maven plugin which updates pom file.
CodePudding user response:
The main functional difference is that the Maven build tool takes care of:
- finding where the particular version of the dependency you want is stored,
- downloading the dependency JAR
- adding the JAR to the build tool's local repo
- telling the IDE's incremental compiler where the JAR is; i.e. via your IDE's Maven integration plugin
By contrast, if you add the dependencies using "Project Structure > Libraries" (or the equivalent in other IDEs, you have to do the above (1. 2. and 4.) yourself, by hand.
Other differences:
- Maven will take care of transitive dependencies.
- Maven can automatically deal with SNAPSHOT dependencies.
- If you do it via the IDE project structure, you are liable to either end up with dependent JARs in your source control repository ... or with other people having to repeat the manual process when they need build your software.
- If you do it via the IDE project structure, you have the problem that different IDEs do it differently. This presents problems if different developers prefer to (or have to!) use different IDEs.
In short, it is better to use Maven or Gradle, or some other build tool that understands dependency resolution ... rather than doing the work manually and then configuring the project libraries using the IDE.
Especially if other programmers need to build your Java application.