wrong version of jar used when running program in IDE

已回答

I have from time to time the problem that the IDE does not use the correct version of a jar when moving from one project to another. Usually the projects are the same but in a different version, already existing in different workspaces. This happens with “own” jars (developed by us) and also with public jars (e. g. guava). Usually it helps to either restart IDE with invalidate cache or switching to a complete different project and switch back again. But it also happened that I couldn't get it running. Then a few days later it worked again without changing anything (working on other projects in the meantime).

Actually a wrong version of guava is used. According to the pom version 28.0-jre should be used. It's only used from transitive dependencies, other transitive dependencies are for version 16.0.1 and 14.0.1

Under external libraries for the project the versions 28.0-jre, 21.0 and 11.0.2 are listed.

When debugging stops at a breakpoint and a class from guava is opened, it points to the class of version 28.0-je under external libraries. But when a method is called which  exists in version 28.0-jre but not in older versions I get a NoSuchMethodError. Examining the classpath (System.getProperties("java.class.path") shows that version 11.0.2 is used, which does not appear in the pom.

This happens not only on my PC but also some colleagues. What could I do to get the IDE using the correct jar?
I am still running 2023.1.4 (ultimate edition), the problem exists since at least 2 years.

 

Upload ID: 2024_03_05_iHVPuC1wVi6t1XXSeJwBtc (screenshots)

0

Hello, Eddie!

Thank you for reporting this!

Based on the description, this might be an issue with IDEA's Native Build System and how it manages classpaths (IDEA-348142).

Could you please share a screenshot of the Run Configuration you are using for debug (feel free to remove any sensitive data)?

0

I am not sure about issue IDE-348142, but the related KT-66203 seems to describe the same problem.

I hope the screenshot shows everything you are interested in (if not, just let me know). I removed only the program arguments.

Upload ID: 2024_03_05_ktNV2f139V4HypMDYLYR3o (file: Run-screenshot-IntelliJ.PNG)

0

Thank you for sharing the screenshot!

That appears to be a Application Run Configuration, is that correct?

If so, those by default are processed by IDEA's Native Build System.

Consider using Maven Run Configurations or options available from the Maven Tool Window.

Let me know if it helps with the issue!

0

I am not sure whether I understood you.

Your suggestion is to build the project this way with maven and then start my application as usial?
I did this - “Delegate IDE build/run actions to Maven”, but it didn't change anything (except very slow performance building the project …).

I am not sure whether I did everything right, when I started my application I had to attach the debugger manually.

BTW, this project is in production stage, only some fixes applied and no pom changes since several years.

0

I apologize for the misunderstanding!

“Delegate IDE build/run actions to Maven” option is a bit of a bruteforce approach, as it delegates everything to Maven.

I was suggesting to create a Maven Run Configuration to run and debug your Project.

That is a different type of the Run Configuration that is processed differently by IDEA:

Please note that you may need exec-maven-plugin in order to run the application.

Performance impact is an unfortunate, but expected side-effect of using Maven as it, unlike IDEA's Native Build System, does not support incremental compilation.

Let me know if such approach would be feasible for you!

0

Thanks, I was able to run my application this way.

I still have two questions: 

 - Is it necessary to have “Delegate IDE build/run actions to Maven” activated?

 - Will the native build be improved in the future or is this the way it works? I am asking because it's really timeconsuming…

0

One more note:

I checked out the project including related projects in a new workspace. In this workspace only the correct version of guava is listed under external libraries.
So the real problem might be another…

It works for me now, but if you have some ideas for narrowing down the problem just let me know.

0

Could you please clarify what you are referring to as checking out the Project in a new workspace?

0

File | New | Project From Version Control

checking out into a new directory.

0

Thank you for the clarification!

In that case that might have been a one-off case of a IDEA's internal caches corruption.

Please do let us know if the issue re-occurs at any point!

0

Just to let you know:

This is not the first time it happens. I saw this more than 5 time in the last 2 years, and several of my colleagues had also the same problem. It does not happen often, but there is obviously a problem.

I didn't report it earlier because I also assumed for a long time that there has only been some damage of the project. But because it only happens when switching between similar projects (in different branches, usually different versions of dependencies in the pom), my feeling is the the IDE get's confused somehow.
And this time it was the first time that it was absolutely not possible to get it running again.

As long as we can solve it by checking out everything again, we can live with it, but if it could be solved it would be nice. ;-)
I know that's not easy as long as the problem can't be reproduced reliable…

0

This issue definitely deserves attention!

However, in order to investigate and resolve it we need it to be present at least in your environment, so we can determine the root cause of it.

So if the issue occurs again, please do not hesitate to let us know, so we can dig further into it!

0

I have had the same issue, when use different versions of dependencies, I thought it was my project issue until run my project form command line with no issue.

The solution works for me is just to delete the .run folder and create Run/Debug Configuration again.

0

请先登录再写评论。