Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain how IntelliJ, Maven and pom.xml work together?

If I add a dependency by entering it in pom.xml, it is added as a "java library" in project structure > libraries. This uses Maven to add the library. Right?

However, in project structure > libraries, there is an option to add Maven projects, but these are not added to pom.xml and appear as maven libraries as opposed to java libraries in the project view. Why? What's the difference?

It's certainly convenient to use new library > from maven because you can search for libraries. However, the libraries not being added to pom.xml seems like a drawback because this way some libraries will be in pom.xml and others not.

Could someone explain how all this works?

like image 663
abc32112 Avatar asked Nov 11 '22 03:11

abc32112


1 Answers

About Maven - its primary goal is to support development with stable state of. In order to attain this goal there are several areas of concern that Maven attempts to deal with:

  • Allowing transparent migration to new features
  • Providing a uniform build system
  • Making the build process easy
  • Providing quality project information

Project Object Model or POM is one of the most important units of work in Maven. As you already know it's an XML file that contains information about the project and configuration details used by Maven to build the project. So yes - If you add .jar as dependency in both POM and Project structure it'll automatically create such in VCS too.

Based on my experience with IntelliJ Idea it's very important to remember to add this new .jar in Subversion too (Right click on .jar > Subversion > Add). A couple of times ItelliJ Idea set it as local change and actually you don't commit this file - and believe me it's very annoying to deal with it. Maybe the most important thing about POM is that it helps with avoiding so called 'Jar hell'. In POM you set goals, so when executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal.

Also as a tip - when updating POM and Maven I prefer to use the FileSystem and cmd. By doing so I've managed to avoid not one-or-two IntelliJ 'misreadings'. Very helpful are also the "Lifecycle" commands. e.g. clean/verify/install

like image 143
ekostadinov Avatar answered Nov 14 '22 22:11

ekostadinov