To answer your question as to why an IDE can't do it, the reason is that in order to do it you need to solve the halting problem.
Of course, the IDE can do it if you limit yourself to a subset that is not fully Turing complete, which is what IDEA does today.
The issue a lot of people have with Gradle is that this subset is not well defined, and it's very easy to do something that works but will get the tools to have problems, and debugging such issues is not particularly entertaining.
IDE does not try to analyze Gradle scripts directly, it works with declarative model that is created by executing Gradle scripts.
Gradle works in two stages:
1. Configuration: scripts execute and produce software model (DAG of tasks essentially).
2. Execution of necessary tasks in the graph.
IDE cannot get the graph by analyzing scripts, but it does not need to: instead it can ask Gradle for the model. The model itself has nothing to do with Turing completeness.
You're not wrong about the halting problem, but the reality is that most people do simple things that the IDE can extract a lot of information about. I.e. it doesn't have to understand a function to make the function fireable from a GUI button, and that is still actually quite useful.
Of course, the IDE can do it if you limit yourself to a subset that is not fully Turing complete, which is what IDEA does today.
The issue a lot of people have with Gradle is that this subset is not well defined, and it's very easy to do something that works but will get the tools to have problems, and debugging such issues is not particularly entertaining.