How to prevent idea from resolving maven dependencies?

Answered

Dear community,

maybe you can give me a piece of advice.

I'm working on the project which is imported from maven. In maven settings I have disabled “Reload project after changes in the build scripts”.

I would like to force Idea NOT to resolve any maven dependencies without my explicit request/action.

Idea tries to re-resolve maven dependencies on many occasions, e.g. when I checkout different branch from GIT, or even when I tried to turn OFFLINE mode for Maven.. first thing Idea tried to do was to re-resolve (some) of the dependencies from the repository. That's from my point of view kind of unexpected.

My problem is, that the libraries in the repository are often updated and I want my project to keep working with the versions I have locally, otherwise it may get broken (e.g. changes in interfaces in libraries) and I need to re-sync the whole project from GIT and maven and build from scratch which takes a lot of time in my case. Sometimes I need to switch to different branch for a while just to cherrypick some changes and create the pull request, but then I want to return back to my original branch and I don't want idea to do auto resolving each time I switch the branch.

So it would be great if there is any option to prevent resolution of dependencies until I really want it (i.e. I click on “Reload all maven projects”). Is there any way how to do that? Offline mode is probably not the best choice, since the switching to offline itself triggers resolving :(

Thanks a lot.

0
5 comments

Hello, Peter!

Thank you for reporting this!

Disabling “Reload project after changes in the build scripts” option should prevent IDEA from running Maven Sync automatically.

I've tried reproducing the behavior you've described, but so far was unable to.

Would you able to share a brief screencast demonstrating the exact chain of actions that result in IDEA running a Maven Sync automatically with “Reload project after changes in the build scripts” option disabled?

0

Hi Roman,

thanks for the reply. Unfortunately I don't think I'm allowed to send recordings of my company computer screen and project. But I think it should be easily reproducible. I just check out different branch from GIT. Since there are differences in pom.xml files, Idea automatically tries to “Read” the maven project of the branch I just switched to. If there are any unresolved dependencies, it tries to resolve it.

The sequence is as following:

- I switch the branch

- Idea: Checking out branch XYZ

- Idea: Scanning files to index

- Idea: Reading maven projects

- Idea: Resolving dependencies

I think the problem is that the disabled setting is: “Reload project after changes in the build scripts”, but it seems that Idea is NOT ”Reloading the project".. it is rather “ONLY” reading maven projects and resolving dependencies… Which is not OK in my case, because although the project itself might not have been reloaded, but libraries which are downloaded from the repository might not match the my current source code, when I switch back to original branch.. The libraries I'm referring to are basically snapshots of the current build, they are not defined as exact version numbers, that's why dependencies get broken so easily. It would help me a lot if I could tell idea, not to resolve any dependencies or not even read maven projects automatically.. I thought that OFFLINE mode is supposed to do so, but when I try to switch to OFFLINE, Idea for some reason tries to do the resolving before it is switched to offline, which itself may break my project :) 

0

Peter,

Thank you for sharing the details!

I was testing the same exact scenario and with “Reload project after changes in the build scripts” option disabled IDEA only runs indexing for me.

Which version of IDEA you currently have installed (Help → About)?

0

IntelliJ IDEA 2023.2.5 (Ultimate Edition)… but I think it depends if there are any changes in the pom files when you switch the branch.. If there are not I also see no background task for it.. but if there are any changes, the poms are being read with “Reading maven projects” background task and if there are unresolved dependencies, it also triggers resolution.

0

Peter,

In my testing I'm switching between two branches and depending on “Reload project after changes in the build scripts” option IDEA either does a full Project Sync or indexing only.

I would suggest to check if the issue persists for you on the latest version of IDEA (2023.3.1) and if it does or if it isn't possible for you to upgrade right now, could you please:

  1. Add #org.jetbrains.idea.maven to Help → Diagnostic Tools → Debug Log Settings
  2. Reproduce the issue and mark the exact time when the Project Sync was occurring
  3. Send me IDEA Logs (Help → Collect Logs and Diagnostic Data) via https://uploads.jetbrains.com/ along with the timestamp of when exactly the issue was occurring.
0

Please sign in to leave a comment.