In new Maven projects in IntelliJ, I see 2 ways of declaring new dependencies:
- Manually editing the pom.xml file, adding a
<dependency/>
declaration. This automatically (maven auto-import is on) addsMaven: ...
entries to the project .iml file and all is well. - Using the
File -> Project Structure -> Dependencies
menu. This only creates entries in the .iml file.
This seems like unwanted behavior. IntelliJ doesn't overwrite the .iml file when importing the pom.xml Maven file, but merges dependencies from the pom.xml and additionally-defined ones from the .iml.
I want to enforce a single way of adding dependencies in my team (using pom.xml only, for external mvn builds), and the ability to bypass the pom.xml and directly add dependencies to the .iml creates the illusion of a valid build (when in fact, it is not).
Am I missing something? How can I enforce one way of adding dependencies? Is there a way through which IntelliJ will add dependencies to the pom.xml file instead of the .iml files?
EDIT
In this question (IntelliJ IDEA + Maven what is the need for dependency entries in an iml file?) it is claimed that
This can be also used to experiment with dependencies without changing the pom.xml. Note that all the modifications you make will be reverted on next Maven import.
But this is not the behavior I see. The .iml file doesn't get reverted, but merged.