Friday, January 15, 2016

Maven Setup in IntelliJ IDEA

On Mac OS X

Mac OS X bundles its own version of Maven.  So does IntelliJ.  I installed a third, newer version, which is the one I use from the command line.

When I check which Maven I'm using on the command line ("which mvn") it shows /opt/maven/bin/mvn.

When I check the version ("mvn -v") it shows the Maven home directory is /opt/maven.

By default IntelliJ uses the Mac OS X-installed Maven.  This causes problems when creating a project from existing Maven sources (pom.xml) because it can't find the repository.

If you see numerous errors related to not being able to find or use dependencies when you compile a project with Maven in IntelliJ and you can see the .jar files it should be using are in the local repository (/Users/username/.m2/repository/...) but Maven can't see them, check which Maven it's using.

Navigate to IntelliJ IDEA > Preferences.  Select Build, Execution, Deployment > Build Tools > Maven.  The Maven home directory and version should be the same as the one reported when you do "mvn -v" and the User settings file and Local repository should typically be located under .m2 in your user home directory; for example, /Users/myuser/.m2/settings.xml and /Users/myuser/.m2/repository. If they are not, set them to the one you use.

If the directory is hidden, you can select the "Show Hidden Files and Directories" button.


Now you will be able to select a hidden directory.


For showing hidden files and directories in Finder (outside of IntelliJ), see "Show Hidden Folders / Directories in Finder".

When the maven home directory is selected, IntelliJ will display the version number so you can verify it.


Once Maven is set correctly in IntelliJ all the errors should resolve.

No comments:

Post a Comment

DBeaver vs. SQL Developer: DBeaver fail!

DBeaver claims to be the best database editor. Thanks to some bad UI, something as simple as switching the database schema in the SQL editor...