Intellij gradle cache resetted for old project.
已回答
When I open a project which I haven't open for a while, I need to re-download all gradle dependencies again. This happens sometimes as I don't open the project frequently, but makes me annoying when there are lots of dependencies need to be downloaded.
As I know, the gradle cache doesn't have a limit for its (disk) size, so I think this is caused by intellij. If it is right, can I disable to keep caches forever ? or it is not, how can I prevent the dependencies to be resetted ?
请先登录再写评论。
Hello!
Thank you for reporting this!
As far as I'm aware, IDEA does not run any kind of maintenance/retention on Gradle User Home.
Is there any other software that uses Gradle in your environment?
Roman Vatagin Hi, I'm sorry for late reply.
I only uses intellij for gradle. Actually, It is hard to show you what is going on, but I will explain it very specifically.(And ahead, sorry for bad english. Please excuse me)
1. So.. as I mentioned before, this happens usually when I open a project which has not been opened for a while
2. When I open the project, the startup initialization proceed → scanning file indexes, gradle build, gradle configuring projects.. and etc.
3. After all startup tasks done, there are lots of compilation error, especially for “import” clauses. For example, Let's say I have a `Hello` public class java file, and in this file, there is a import clause for a library class, like `import org.foo.bar.Baz`. In the past, there was no compilation error, but now it shows “Cannot resolve symbol ‘foo’ ".
5. I think, This means that the library class has not been loaded on intellij during startup. In this situation, I need to open my `build.gradle`, and click the refresh button on the top-right side of panel. And then, now it starts to re-download the artifacts following gradle dependencies
If it was about only the problem for “import” things, it is fine, as it would take only a few seconds. However, re-downloading every artifacts is quite uncomfortable, because it takes a very long time.(With a big project, I need to wait for almost a half hour!) I've been experienced this for many years, but as my several private projects getting bigger, this situation irritates me quite a lot. Also, I don't think this is a bug, instead, I assumed this is intended one. So I'm asking you : How can I disable it? If it is not a feature, how can I keep dependencies ?
chalee Thank you for sharing the details!
If the dependencies have to be downloaded on Gradle Sync that would indicate that they are not available in Gradle User Home.
IDEA interacts with Gradle-based Projects via a Gradle Daemon and, while there's some custom logic that IDEA employs, we tend to stick very closely to Gradle's workflows.
Could you please do the following test: next time you have to work with a Project, that has not been opened for a while, instead of opening it in IDEA, try running Gradle Task like
verify
orcompile
against it from OS Command Prompt.Check if Gradle has to download any dependencies. If it does not - try opening the Project with IDEA.
Roman Vatagin Thank you for your reply.
I tried your suggestion, and this also downloads the artifacts. I digged into into this problem, and finally found out an issue from gradle github (https://github.com/gradle/gradle/issues/7018). There has been a long time discussion, and it says (as I understand)
1. Originally, gradle has no cache cleanup strategies before.
2. Once, they updated to cleanup the caches by 7 or 30 days periods. (And this “days” has been fixed for years)
3. As the version of gradle 8.0, now it can be configurable.
I also found a user-guide for this configuration here (https://docs.gradle.org/8.0-rc-3/userguide/directory_layout.html#dir:gradle_user_home:configure_cache_cleanup), so I'm gonna try this, leaving artifacts un-touched for a couple of weeks…
If you have any suggestion or thoughts for this, please share with me. Thank you.
chalee This seems like the most likely culprit!
Let me know if adjusting / disabling the retention helps with the issue!