My Experiences with Maven in IntelliJ IDEA and NetBeans IDE
Join the DZone community and get the full member experience.
Join For FreeWith IntelliJ IDEA supporting a fully-functional integration with Maven, you can automate your entire building process.
The result is that you can create a new Maven project as well as easily handle multi-module projects.
Netbeans IDE on the other hand, simplifies the development of mobile applications as well as web and desktop applications using Java and HTML5.
So imagine my surprise when some weeks ago, I saw a colleague fighting IntelliJ's Maven support. A dependency was not detected by IntelliJ's Maven support and to fix it, he had to remove the dependency from the POM, save it, add it back to the POM and save it again. Hmmm... somehow not quite optimal.
This was the reason for me to take a look at IntelliJ's Maven support and compare some points with the support provided by NetBeans.
Let’s look first at how IntelliJ IDEA can support an integration with Maven that is fully functional. This will assist you in automating the whole build.
It doesn’t matter whether you wish to create a totally new Maven project, synchronize with an existing open project or add Maven support to existing IntelliJ IDEA projects. You can also manage projects that are multi-module.
Creating New Maven Projects
These are the steps I’d follow to create a new Maven Project.
If you’re starting from scratch and there’s no project open currently in IntelliJ IDEA, go to the Welcome screen and click on New Project. Alternatively, you can select File and then create a new project for the main menu.
Once you’ve created your new project, you must name it and if you require it, change its location. You’ll want to create the Git repository, so select the new project for placement under version control. Just be aware that you can do this at any time later in the build.
Don’t forget to tick the box.
Your project requires a language selection, so do that as well as add any other languages you may want via plugins. You do this by clicking “App>general add”.
Under "build system", select Maven followed by specifying the project’s SDK. Or, you can go with the default or JDK.
While it is not necessary, it’s a good idea to have a file with a basic sample code, so tick the “add sample code” box.
Don’t neglect to specify Maven’s coordinates, which are included in the pom.xml file. You’ll find these in the advanced settings where a new project package is identified in the Groupid box and the project name is specified via the Artifactid box contents.
Maven naming conventions follow Jav’s package name rules. This is in the format of a reversed domain name that you control e.g. org.apache.maven.
While the naming conventions are not enforced, you’ll have a hard time getting names that don’t follow the rules in the Maven central repository, especially if it is a single word used for group IDs.
When you’ve finished your selections, then click “create”.
Handling Maven Projects
If you open a Maven project in IntelliJ, IntelliJ still generates a default project folder (".idea") and file (".iml").
This means IntelliJ must always ensure that data in the POM is kept in sync with its proprietary structures. However, IntelliJ only handles one direction. Changes in the POM are recognized and the project settings are in sync most times.
But if you change something in the project settings, these changes are not reflected in the POM. So, as my colleague experienced, you have to do it twice.
Also, IntelliJ lists the "target" folder and ".idea" project settings folder in the logical project view, which is not useful most of the time.
In IntelliJIDEA, the Maven project pom.xml file has a compiler included as well as the target Java version. There’s also a Maven tool window and any dependencies that are required to start work.
Just bear in mind that the version of Java that is specified in the pom.xml file will, in all likelihood, override the "JDK for importer" option’s specification version. You can find this in the Maven settings.
Configure Maven Settings
To make things easier, configure your Maven settings before opening new projects.
Configuring IntelliJ IDEA to display the Maven settings prior to opening an existing project that is being opened for the first time in IntelliJ IDEA is done at the application level. Once set, they’ll appear for any new project that you open.
On the Welcome screen, “All settings” under the customize option. You can also access it from the main menu by selecting “file”, then “new project setup” followed by “preferences for new projects.”
In the “preferences” dialog under settings, choose “build”, then “execution”. Under deployment, select Maven as your option under “build tools.”
Now go to the Maven settings dialog and make the selection “Show settings dialog for new Maven projects”. You can then click OK and your changes will be saved for all future projects.
What this does is, each time you open new projects, the Maven settings dialog is displayed by IntelliJ IDEA and you can then specify the local Maven repository’s location as well as a user settings file.
In contrast, NetBeans uses the POM for pretty much everything. The Maven POM file defines the project, as shown below.
If you change something in the project settings, it is directly stored in the POM. Only in rare cases, e.g., if you redefine actions, does NetBeans need to create a specific file.
NetBeans only shows important information in the Projects window, as shown above. However, if you do want to see the Maven "target" folder, you can easily switch to the Files tab:
Building Maven Projects
When you build a Maven project in IntelliJ, with the default IDE commands, Maven is not used for the build process.
The same goes for tests. If you are using different profiles for local development and your continuous integration server, you have to use Intellij's Maven integration tab to build and test your project with Maven. This is really ugly because you cannot use all the shortcuts that make life easier.
NetBeans uses Maven for all that. You can simply press F11 or use the default toolbar button or menu item to build your applications with Maven.
This same action works whether you are using Maven, a plain NetBeans Ant build script, or Gradle. It’s always the same consistent procedure.
You can even change the Maven command that is used to build the project via F11. You are completely free to configure what you need:
Executing Maven Goals
Running Maven goals in IntelliJ displays a dialog with just two text fields and you have to type all the Maven parameters by hand.
Hey man, it could be so much easier.
Running a custom goal in NetBeans gives you a fantastic dialog with lots of possibilities. You can choose the profile, add properties, and even save everything to run it again later.
This saves a lot of work.
Conclusion
There are many smaller issues that show that NetBeans has a smoother Maven integration than offered by IntelliJ.
My impression is that IntelliJ's Maven support is just an extension to its default project management system since It still needs the default IntelliJ project folders and files. Meanwhile, NetBeans provides a much deeper and more complete integration.
One more thing. I’m not an IntelliJ user so please forgive me if there is a mistake in my observations.
I'm also not trying to start a new IDE war. What I want to do by means of this article is to get readers to think out of the box. If you are familiar with your IDE, that is great. If you are productive with your IDE, that is great. But if you think an IDE needs to be expensive in order to be a good product, you are totally wrong and should definitely give NetBeans a try.
Thorsten Marx is a product manager and developer at e-Spirit AG in Germany.
Opinions expressed by DZone contributors are their own.
Comments