DEV Community

Grigoriy Myasoedov
Grigoriy Myasoedov

Posted on • Edited on

My Intellij IDEA plugin for Maven support - Easy Maven

Hello, my name is Grigory. I am a Java developer and had experience working at JetBrains (for a short time). There I was developing and supporting the Maven plugin. One of the most common problems I dealt with was: "The Maven project was successfully built via the command line, but was not imported into IDEA". Usually such problems occur when using additional plugins to resolve dependencies. For example, the eclipse OSGI project (and not only). For example, here is a simple OSGI project that is not imported by the IDEA Maven plugin, but is imported by Easy Maven.

So let me introduce you to my plugin for working with Maven for IDEA - Easy Maven, which is designed to solve this problem. If you have problems with importing a Maven project into IDEA, I suggest you try my plugin:

IDEA Bundled Maven-plugin problems
I am familiar with the source codes of the IDEA bundled Maven-plugin (IBMP). IBMP for resolving dependencies and obtaining project models uses its own custom process, which is somewhat reminiscent of a maven daemon. It is built from low-level Maven service components: ProjectBuilder, ModelInterpolator, ProjectDependenciesResolver and etc.
Due to complete customization and reuse of the their Maven process, they received the following advantages:

  • the process is more lightweight than the original maven;
  • due to this, the speed of resolving dependencies and obtaining a projects model is higher;
  • it's easier to add features for the IDE.

But there are also problems:

To summarize, we can say that the main problem is IBMP that its process for resolving dependencies differs from the original Maven process when launched via the command line.

My idea
So I had an idea - why not resolve the project's dependencies using a native Maven plugin and thereby use the full original Maven lifecycle.
Let's look at an example of the simplest Maven plugin:

@Mojo(
    name = "my_task_name", defaultPhase = NONE,
    aggregator = true, requiresDependencyResolution = TEST
)
public class ResolveProjectMojo extends AbstractMojo {}
Enter fullscreen mode Exit fullscreen mode

Even such a simple plugin, thanks to the parameter requiresDependencyResolution = TEST (TEST is the top-level scope), will download all dependencies if necessary and add resolved artifacts to the Maven project model. My Maven-plugin code is not much more complicated than this example. Its main idea is to resolve dependencies and extracting the configuration of a number of plugins necessary for the correct import of the project model into IDEA.(maven-compiler-plugin, build-helper-maven-plugin and etc). As a result, I wrote my own plugin for Intellij IDEA to support Maven - Easy Maven, which uses the native Maven plugin to resolve dependencies.

Also, I moved the maven-plugin to a separate repository on GitHub and published the artifact in Maven Central.

The project import process consists of the following steps:

  • From the IDEA plugin I start the simple maven process (run my maven task - maven-model-reader-plugin:resolve);
  • The result project model, with all resolved dependencies, is returned via file in JSON format;
  • Data from the file is loaded into the IDEA project structure.

This is what the import process looks like in the build window. We see the full Maven log: how the process was launched and what is happening in it.

As a result we get:

  • a very simple process of interacting with Maven, which consists of running the maven goal;
  • a full Maven original life cycle with all current features, which excludes errors from the category - we forgot something when importing the project model into IDEA;
  • a full native Maven log, which makes it easier to maintain the plugin and solve problems.

Additional features

  • Delegating tasks execution to Maven Daemon wiki. Since any action in Easy Maven is an execution of a Maven goal (importing a project into IDEA, running any build phase, analyzing dependencies, etc.), we can easily delegate this to the Maven daemon and increase the speed of working with the project.
  • Maven 4 support. Since I use the native Maven plugin to resolve dependencies, I immediately get Maven 4 support without doing anything special for this. Because it is fully compatible with Maven 3 in terms of plugin API. For example, you can look at the project. It uses a new tag "subprojects" from Maven 4. Until version 2025.1, it was not imported correctly to IDEA and required fixes. While in Easy Maven it works immediately, without additional logic, thanks to the plugin. But even in version 2025.1, it does not recognize correctly the content root path, which is correct and this again requires fixes. In my plugin, there is no such problem again. And I did not create any special logic for this.
  • Using the whole project context for task execution wiki.
  • Android Studio support. Oddly enough, but most of the downloads of my plugin are Android Studio users. Android Studio does not have built-in support for Maven, but users need it and Easy Maven plugin allows you to solve this problem.
  • Allows you to set additional Maven parameters for import in Easy Maven settings. Because project import is the regular Maven task. For example, in project ajdt, dependencies are resolved during compilation. In Easy Maven, we can simply specify the "compile" parameter in the settings(Import args) and the project is successfully imported. While the bundled Maven plugin does not import this project at all.
  • Readonly mode. Allows you to open projects without downloading a bulk of dependencies, if you just need to read and navigate the code. In the IDEA it is much more comfortable to do this then in Web.
  • Refused to render the full dependency tree in the build tool window. As a result, it renders much faster, especially noticeable on large projects, where there are thousands of dependencies and it is not convenient to search in it. Instead there is one node - “dependencies”. Click to open the Dependency Analyzer window with a convenient mechanism for searching and analyzing dependencies, which lazily loads the dependency tree. As a result, Easy-Maven-plugin stores less state.

Results of projects import time measurements
IDEA 2023.2, -Xmx4g, i7-10875H, 32gb.

EasyMaven (seconds) IDEA Maven (seconds)
Quarkus (~1100 modules) 110 60
Dbeaver (~150 modules) 60 - (Error)
Spring-Boot-2.1.x (~100 modules) 20 12
Maven 3.8.x (15 modules) 2 2
  • all dependencies at the time of measurements were already in the local repository;

In general, the IDEA Maven plugin, due to its customization and incremental update functionality, works faster, but this is noticeable on large projects. On small projects with up to 50 modules, import times are comparable. But the main goal of Easy Maven is to correctly import a project into IDEA.

Result
Easy Maven plugin has fewer features, no Maven indexes, no incremental import, fewer quick fixes, but it is much simpler and, in theory, more stable, stores less state and consumes less memory.
For example, maven indexes have a number of problems in the IBMP and affect performance. Instead of calculating and storing maven-indexes myself, I use HTTP requests to the server https://search.maven.org. Also, my plugin has fewer problems with backward compatibility, the Maven-plugin API is much more stable and changes less often. And uses a full original Maven lifecycle to resolve dependencies.
If you have problems with importing a Maven project into IDEA with a bundled maven-plugin or you are just interested in trying my plugin, then I would be glad to receive any feedback. If we find any problems, feel free to create an issue.
Required version of IntelliJ IDEA 2022.2+ (but there is also a cut-down port for 2021.3)

Top comments (0)