IntelliJ IDEA writes to Maven repository but does not read.

Answered

Issue:

  • I configured Local Repository in the Maven settings.
  • Using the IntelliJ Maven popup (right top of IDE) I do Lifecycle/install for one of my modules and it indeed creates the JAR and places it in the repository (if I have no dependencies on other modules).
  • BUT:  When I try to do the same on for a module with a dependency on a JAR from the local repository, I get the “Could not resolve dependency…” error, where it mentions that it cannot find it in https://repo.maven.apache.org/maven2  even though the file is right there in the local repository and was built just 5 minutes earlier.

Is this a bug in Ultimate Edition 2023.3.3?  Or perhaps a bad default that makes it ignore the local repository? (this is a fresh install on a new computer… old one works perfectly)

1
16 comments

Hello,

Does this dependency usages are resolved in code? Could you please share idea.log ("Help | Show Log in…") after reproducing the issue and facing the issue to check recorded events?

0

OK, more details:

The project was originally based on an series of projects from an Eclipse workspace and converted into the current Project/Module structure over a year ago on another PC.  It is all Maven/Java 17 based.

This project then was copied from that PC to the one having trouble.  The first copy attempt was done by “cloning from version control” (GitHub), when it didn't work I deleted it and used the “copy the Project folder from the old IntelliJ and then Open it” method.  No code at all was changed.  Both methods produced the exact same issues.  The problem clearly 

Project structure:

- Maven project with modules. 

- Main Project = Parent BOM-POM, no code.

- Common library module:  A single module that contains library code built into a JAR that is reused by every Application module.

- Dependencies modules:  Intermediate BOM-POMs, no code, POM has the Main Project as its parent.

- Application modules:  Depending on the type of component each of these modules is a sub-module of a Dependency module and its POM has that Dependency module as its parent.  All of them have the Common library module as a dependency.  Some of these application modules build into library JARs, some into SpringBoot application JARs (with embedded Tomcat), some into webapps or REST WAR components that get deployed onto a Tomcat server.

Symptoms:

1) The most glaring sign of something amiss is the Maven panel of IntelliJ.  

- On the original PC you see ONE project, the main one.  You have to drill down to see the Dependency modules, and drill down further to see the individual Application modules.  At any of these levels you see the lifecycle entry, which will do a Maven build for ALL of its sub-modules.

- On the copied PC the Maven panel shows ALL of the modules at once.  This would be annoying but fine *if* it worked.

2) The most serious problem is the failure for the build to see items in the local repository.  For example:

- When I built the Common library module, it worked fine.  A maven Install built and placed the JAR in the local repository.

- When I tried to build one of the Application modules it failed.  The error indicated that it could not find the Common library module in https://repo.maven.apache.org/maven2 .  Of course it is not there… it is in the local repository, but IntelliJ is refusing to look for it there.

 

0

Bruno,

It's hard to investigate the issue without project example. Could you please provide one? Generally, you may remove all code from your project and provide it as I need only common project structure. You may share files via https://uploads.jetbrains.com/ form. 

0

I was able to fix the issue, but it required installing Maven at the command line, building “the whole project from the top POM” outside of IntelliJ from the command line “once” and after that… IntelliJ started building fine.

I suspect the issue involves “navigating down through the POMs in a single full build/install, from the top of the project down to the implementation modules”.  Native Maven did it fine, but IntelliJ seemed to choke on it.

Creating an empty project this nested would be very time consuming.  Since it seems to be working now… I'll call this “resolved” even though I strongly suspect a bug.

0

Bruno,

Thanks for information! I'll pass it to developers for investigation.

0

Hi there!

I am running into a *really* similar issue. I have a multi-module legacy Maven project, which has in any case been working perfectly within IntelliJ for the last few years. 

Last week I had to install everything fresh on a new computer, with IntelliJ Ultimate 2023.3.3, and if I try to run the install goal on the parent module (or on any other module, for that matter), I get a error: package org.apache.log4j does not exist error (and then a few more like it), when the dependency is there, and IntelliJ is showing it both under the module dependencies and under the project dependencies.

If I run the install goal manually from the command line, even if using the embedded IntelliJ Maven to run it, it builds the project and it works perfectly.

And indeed, after that, I can run another install from IntelliJ and it works… until I run a clean goal from IntelliJ, and then we're back to the package does not exist error.

So, this definitely looks like a bug in IntelliJ 2023.3.3… or a really, really weird coincidence.

Please let me know if there is any more information I can provide.

Thank you!

0

It would be great if you could provide sample project example for faster investigation. 

0

Hi @...,

I have been able to generate a sample project, where should I upload it?

Thank you!

0

Nevermind, I just uploaded it to GitHub, there you go: https://github.com/gonzalo-rodriguez/intellij-maven-issue-test

Importing the pom.xml from the parent project and trying to run clean install from IntelliJ ends up showing an error resolving the log4j library, while on IntelliJ itself it works perfectly.

Hope this helps! :) 

0

Thanks for the example, but it seems to work fine on my side. Here are my steps:

1. Select “Get from VCS”, enter URL and click “Clone”

2. After project opening I got “Maven build scripts found” popup with two modules - test_child and test _parent

3. Click on “Load” on popup

4. Open maven tool window and select “clean” then “install” action (works fine from both mentioned modules) 

0

Thank you, @...

I hadn't tried following those exact steps (I tried it before uploading the project to GitHub), but I did exactly that just now, and got the same result: 

Bruno Genovese is there any way you could try it too, please?

Thank you both!

0

It took me days to get my project to work after reimporting (due to multiple issues that I eventually resolve), and I cannot afford to risk doing the same.  Also, my project structure is quite complex, MainProject as BOM-POM → several intermediate BOM-POMs → actual modules that get built and it would be tricky to replicate it on one computer to re-import on the other.

What I did learn and discover:

1) The method of import made no difference.  The issues happened whether I imported through GitHub or by copying the project folder from old to new computer.

2) The problem happened when the local repository was empty at first.  A full build from the top did not work at first, and partial “maven install” builds didn't either (probably because we'd need the main project to exist and have been built into the local repository before the child projects would recognize it and be able to inherit the parent poms).  It also explains why the project didn't have the  issue on the original PC, as that project got built by creating the main project first, doing its maven install, then the intermediates and maven installing them, and only then were the final modules with the actual code were created… by which time all of their dependencies were in the repository.

3) I *suspect* that the error message where it complains that the package is not on the maven2 repository happens because the build looked at the local, didn't find it, then it looked at maven2 and when it didn't find it there it gave that misleading error message.

4) SOLUTION:  The solution was to install Maven in Windows, pointing the repository to the same location, and executing the project - the one implemented as the BOM-POM that is parent to the intermediate, which are themselves parents to the implementation modules - from the Command Prompt (outside of IntelliJ).  Once I did that I was able to do “maven clean” and “maven install” for that same project inside of IntelliJ (maybe it had to do with creating the whole project structure for the various packages in the repository?  Seems unlikely, but as good as any other theory right now).  Of course, that means that a full maven install is needed at least once before you can do a “maven clean / maven install” for a specific module that you might be working on, or POM parents might be missing.

5) IMPORTANT:  Note that I had no problems with packages that come from the maven2 repository in the first place, not even before resolving my issues.  I notice that your error is with log4j and lang3… those are standard Apache packages that did NOT fail for me, ever.   That makes me suspect that you have additional issues.

6) SECURITY ISSUE:  This has nothing to do with this particular problem, but I noticed that you are using the legacy log4j that has had serious security vulnerabilities for at least a year.  Once you resolve the issue of rebuilding you should seriously consider upgrading to the latest log4j2 even if it is a pain to do (it will likely involve some code changes).

0

Whoa, thank you so much for this, Bruno Genovese!

Just to clarify, I meant if you could try to download the sample project I uploaded to GitHub to see if it failed for you too, not if you could provide your own, which I knew would be hard due to the complex structure of your project.

As for the security issue: you're absolutely right, and I was aware of that, this is a minimum example generated from a seriously legacy project that we're actually in the process of updating now… but thanks a lot for mentioning it, I really appreciate it!

0

Oh, to grab your project.   I will give it a shot if I manage to have some spare time today or tomorrow.

In the meantime… it might be obvious, but mentioning it just in case.  Open the Maven popup (whatever it is called… right upper side of IntelliJ) and do the first 3 top icons:

- Reload All Maven Projects

- Generate Sources and Update Folders for all Projects

- Download Sources and Documentation

I always do that at least once for every project I create/import.  I am NOT a Maven expert and can't explain the “why” but I noticed that doing those things often fixes many issues, just like the Maven Clean / Maven Install cycle.

So probably you already knew of this, but maybe you get lucky and this somehow fixes the issue :)

0

UPDATE:  I had a few minutes, did new project from Version Control, clicked on the 3 Maven "update' buttons I mentioned earlier, then maven clean and maven install on test_parent.   Worked fine and I saw it building both the parent and client.  I also see the two packages in the repository folders.

A last thought:  

I noticed the new project went to the default maven repository location (not the one I normally use for my projects).  It seems that IntelliJ resets the projects location back to the default every time you create a new project unless you manually override it at creation.  

So… Could there be a conflict between some path set explicitly in your project's .POMs and the actual location of the repository?

0

Whoa. 

I had a whole response written, complete with screenshots and stuff, saying that no matter what I tried it still didn't work (except from the terminal, it always worked from the terminal, even from within IntelliJ), and then something Bruno Genovese said just “clicked” in my head.

I had my maven repository at the default system location (c:\Users\{username}\.m2\repository), but this is a new Windows 11 installation, and my username was generated automatically to be my full name (!) (well, minus a character, because I guess the character limit is 20)… with the accented i (í) character in both my surnames.

So I thought: well, encoding has neeeeeeeeeeeever been an issue in a software project (🙄), but what would happen if I just moved the local repository to a folder with a more standard name, like, say, c:\m2-repository?

And what happened, of course, was that it worked from IntelliJ, first try, both on the test project and on the original one.

So…

Bruno Genovese, thank you SO MUCH for your time and your help with this.

@..., thank you as well, of course, and I guess there was a bug here after all: IntelliJ doesn't like the local maven repository to be in a folder with non-standard characters. But this is only for maven, I have other projects with gradle reading from the same repository, and they work like a charm.

And to myself: time to follow one of the 42-step tutorials on “how to change your Windows 11 username”, just in case :) 

Thanks again!

0

Please sign in to leave a comment.