Gradle toggling between 2 missing dependencies on refresh
I am using Intellij 2017.2.5 Ultimate Edition.
I have a Gradle multiproject build that pulls in several dependencies.
Whenever I modify a build.gradle file in any of the subprojects, Intellij asks me if I want to import changes. This never works, I always have to refresh all dependencies from the Gradle tool window, and usually several times to get the project to start compiling again.
This was always painful, but now several team members are getting permanently stuck with a failing build, where after a Gradle Refresh a specific dependency just disappears from the Project->External Libraries list. Builds fail because of ClassNotFoundException on the missing classes from that dependency. Clicking Gradle Refresh again causes that dependency to reappear inside the Project->External Libraries, but now a different dependency is now missing. Clicking Refresh again toggles back to the original missing dependency, and so on.
I have tried using 'gradle idea' to generate new files and I've tried File -> Invalidate Caches/Restart. Neither of these work.
I'm stuck and have no idea how to debug. The command line gradle works flawlessly.
Please offer some advice on how I can get figure out what is going on. There is nothing inside idea.log or build.log, and there are no instructions that I can find to turn up the logging level for those.
Please sign in to leave a comment.
Ok I'm onto something at least after some trial and error. I checked the dependency in question and when you expand it inside the Project view, it shows 2 jar files. One is under the gradle cache directory, the other under the maven .m2/repository directory.
Deleting the m2 and refreshing now causes the dependency to stay there at all times and not toggle between them. This is not a great workaround as I have maven and gradle projects with overlapping dependencies. Any insight as to why Intellij would pull in both locations for a dependency? And why that causes issues?
Hard to say what's the problem without a reproducible test case.
I understand that for sure, but I cannot share the project.
I'm looking for help to diagnose the issue myself.
1. Is there any way to log what happens when Intellij does its own gradle configuration parsing/refreshing? build.log and idea.log show nothing even with debug turned on. Is there any other way to get information about this?
2. Is there any reason that Intellij would show both repository locations (m2 and gradle) under the project list? This seems to be highly correlated with failures on that library. Are there any known issues with duplicate libraries across both? Shouldn't Intellij stop searching once it finds one of the libraries in the first defined repo?
Try with https://www.jetbrains.com/idea/nextversion/ . It has improved logging for Gradle projects import.
Also check idea.log: https://intellij-support.jetbrains.com/hc/articles/207241085.
There is at least one issue with the duplicated dependencies: https://youtrack.jetbrains.com/issue/IDEA-176361.
Exactly the same problem I experienced (I use gradle-intellij-plugin)
Here is what I posted on that plugin's gitter
https://gitter.im/JetBrains/gradle-intellij-plugin?at=5b74d0995ec2bc174f04c378
I had a similar problem today. However, there are two noteworthy differences.
So it basically looks like this:
Every time I pressed on Reload All Gradle Projects, module C toggled between being detected as dependency of module A or module B. I also noticed that IntelliJ did not detect any dependencies for module C, not even the JDK.
After I deleted module C from Project Structure / Modules and pressed on Reload All Gradle Projects, the Project Structure / Modules View got confused somehow. I got module C two times (once with and once without dependencies) in the hierarchy and every other module was no-longer showing any dependencies except the JDK. Even so IntelliJ did not show the dependencies anymore, IntelliJ was still aware of them since the classpath on compilation and execution was still constructed accordingly. Module C was also still toggled on ever reload since every usage of the library was alternating between marked as error or not after every reload.
I finally closed IntelliJ, executed `git clean -Xdf` and re-imported the project. Now everything is working again.
>After I deleted module C from Project Structure / Modules
Please do not make manual project structure changes in the IDE UI for Maven/Gradel based project, since IDE will reset them on the next Reload from Gradle(Maven) build configuration file.
IDE will set up the dependency on a module if build Gradle script have them configured as project dependencies.
Andrey Dernov, I know. I usually don't change the project structure in the UI of the IDE. In this case, I deleted the module as a workaround to trigger IntelliJ to re-create the module during the Reload. But this did not work as mentioned above. I also have all dependencies configured in the Gradle files correctly. At the end, IntelliJ even detected them (with this one exception) from the Gradle project during Reload, IntelliJ just did not show them in the Project Structure View. Anyway, deleting the project configuration and re-importing the project fixed the problem.