IntelliJ and Maven: poor and unreliable integration
I have a java project with Maven dependencies (for rosjava libraries). I created that sample project to illustrate how to start developing java applications with the rosjava libraries from scratch some time ago; I already had many issues to get it running by then, and created a tutorial for people to make the setup quickly everytime a new project with such dependencies was needed.
Now I wanted to have another project with the same structure (the same dependencies), and therefore I created a new project, added the Maven framework support, but things seem not to work properly. In my opinion, it should be as easy as copying/replacing the POM.xml into the new intellij project, and allow it to update the dependencies, but it is not the case. Here are the main concerns and observations:
1. as far as I know, it is not possible to add Maven repositories using the UI for settings. I only managed to do it by editing the POM.xml directly and writing the necessary <repository> tags, etc. Ok, at least there is a quick workaround, and I see the repository is shown in the GUI settings. Anyway, it looks nice having a GUI just to show that although it cannot be manipulate.
2. Following point 1, the GUI with the search box for adding Maven libraries in the project structure window does not find anything. Only finds whatever in the maven central is, but not in the added repository.
3. If I include the dependency entries directly in the POM.xml, check that the the Auto-import is enabled, and I sync the file, and call the reimport, then it does not have the expected result. The libraries are not added and the GUI does not show any added library. This used to work in the past, but not any more.
4. Moreover, when I code anything using the classes that are supposed to be in the imported libraries, IntelliJ reports with red colours that the class is not found, etc. This is expected as I could not include the library dependencies, but the intriguing part is when the smart wizard associated to these errors propose the action of "Adding Maven dependency...". It brings us to a window that shows the depencies (including versions) that contain such class and it manages to find and show the depencies (including versions that I don't have in my local repo) and eventually adds a new entry in the POM.xml (it doesn't control for duplicates). Despite finding dependecies, they are not still visualized as librearies in the project structure GUI, and indeed, IntelliJ does not compile the project.
5. as said above, I have a sample project that compiles and works (this is weird; in the existing one works but not for the new). As I had all the dependencies in the local repo of maven, I just copied the .jar needed to a libs folder and imported into the new/replica project, so that I don't have to use the Maven functionality. This works for the new project, although it is not convenient as dependencies have to be handled manually, and specially because there is another previous project in the same computer that still compiles, etc. This proves that the .jar files in the local repo are no corrupted.
If there is anybody with a clear view and understanding of how this works, some help would be helpful and appreciated.
cheers
Please sign in to leave a comment.
Some of your concerns already have open tickets at https://youtrack.jetbrains.com/issues/IDEA (like poor library search and no UI support for managing repositories and dependencies).
There is also a known issue in 2017.2 version that can causes the dependencies to not resolve after you add them to pom.xml, see https://stackoverflow.com/a/45244002/104891 for the solution.
File | Invalidate Caches may also help.
thank you for your quick response. I just updated to the last version (2017.2) and then the Invalidate Caches worked after a while and clicking on reimport.
I have to say that the Invalidate Caches used to work in some previous version facing similar issues, but for some reason with the version 2016.3/4 was not working any more. This kind of randomness is very frustrating and introduces high uncertainty. My experience using IntelliJ during this past year (with several versions and updates 2016.x and 2017.x) is that the process usually breaks down without apparent reason. I hope it becomes functional and reliable soon.
all the best