Quick revision
The short answer
IntelliJ IDEA and Eclipse import a Gradle build through Gradle's Tooling API: the IDE asks Gradle to configure the build and return its model, projects, source sets and dependencies, and creates its own modules from that, so the build is the source of truth. IntelliJ can then either delegate build and run actions to Gradle, which is most consistent with CI, or use its own compiler; Eclipse integrates through the Buildship plugin. Java toolchains, declared as java { toolchain { languageVersion = JavaLanguageVersion.of(25) } }, tell Gradle which JDK to compile and test with, independent of the JDK running Gradle, and Gradle can download it through a toolchain resolver.
What to remember
In this answer, we saw that IDEs import a Gradle build through the Tooling API, letting Gradle configure the build and creating their modules and dependencies from its model, so the build stays the source of truth. IntelliJ IDEA can delegate build and run to Gradle, which is most consistent with CI, or use its own compiler, and Eclipse integrates through Buildship. Java toolchains, declared with java { toolchain { languageVersion = JavaLanguageVersion.of(25) } }, choose the JDK used to compile and test, downloading it through a resolver if configured, and generated IDE files stay out of version control.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
IntelliJ IDEA and Eclipse import a Gradle build through Gradle's Tooling API: the IDE asks Gradle to configure the build and return its model, projects, source sets and dependencies, and creates its own modules from that, so the build is the source of truth. IntelliJ can then either delegate build and run actions to Gradle, which is most consistent with CI, or use its own compiler; Eclipse integrates through the Buildship plugin. Java toolchains, declared as java { toolchain { languageVersion = JavaLanguageVersion.of(25) } }, tell Gradle which JDK to compile and test with, independent of the JDK running Gradle, and Gradle can download it through a toolchain resolver.
Why this question is asked
Most developers meet Gradle through their IDE, not the command line. When the IDE and the build disagree, the result is code that compiles in the editor and fails in CI, or tests that pass in one and not the other. Knowing how the integration works, and what toolchains do, prevents most of those surprises. Interviewers ask this junior question to check that we treat the Gradle build as the single source of truth. In this answer, we will see how IDEs import a Gradle build, the choice between delegating to Gradle and using the IDE's compiler, Eclipse's Buildship, what toolchains solve and how to configure them, and why generated IDE files should stay out of version control.
1How an IDE Imports a Gradle Build
Gradle offers the Tooling API, a library that other programs use to run Gradle and ask it questions. When we open a project in IntelliJ IDEA, the IDE uses the Tooling API to start a Gradle daemon with the project's wrapper version, run the settings and build scripts, and ask for a model of the build: which projects exist, their source directories, their dependencies with resolved versions, the Java version, and the tasks.
The IDE then creates its own internal modules and libraries from that model. That is why changing build.gradle.kts shows a prompt to reload the Gradle project: the IDE has a copy of the model and needs to ask Gradle again. It is also why a broken build script means the IDE cannot import the project at all.
7 messages in order. Play them, or step through them one at a time.
After a build script change, reloading repeats the first five steps.
Notice that the IDE never reads build.gradle.kts itself to work out dependencies; Gradle does all the configuration, so plugins, platforms, catalogs and conventions apply exactly as they do on the command line.
2Delegating to Gradle or Using IntelliJ's Compiler
Once the project is imported, IntelliJ IDEA has a setting for how it builds and runs code: Build and run using Gradle, or IntelliJ IDEA. With Gradle, clicking Run on a test or main class runs the corresponding Gradle task, so the same compiler settings, annotation processors, generated sources, resource processing and test configuration apply as in CI. With IntelliJ IDEA, the IDE compiles with its own build system using the imported model, which can be faster for small incremental changes.
Delegation is the safer default for most teams, because it removes a whole class of IDE-only differences: a code generator that runs as a Gradle task, a test JVM argument set in the convention plugin, or a processResources filter. Using IntelliJ's own build is fine when the build is simple and speed in the editor matters, as long as we remember that CI runs Gradle.
| Option | Strength | Risk |
|---|---|---|
| Gradle (delegate) | Same tasks, settings and generators as CI | Each run goes through Gradle; a little slower |
| IntelliJ IDEA | Fast incremental compile in the editor | May skip custom tasks or settings from the build |
3Eclipse and Buildship
In Eclipse, Gradle integration comes from Buildship, an Eclipse plugin built on the same Tooling API. Importing a project with File, Import, Existing Gradle Project asks Gradle for the model and creates Eclipse projects and classpath containers from it. Buildship adds a Gradle Tasks view to run tasks, and a Refresh Gradle Project action that plays the same role as IntelliJ's reload.
Eclipse compiles with its own compiler, ECJ, during editing, so the same caution applies: the authoritative build is the one Gradle runs. Gradle also has an older eclipse plugin that generates .project and .classpath files, but with Buildship it is normally not needed.
4What Java Toolchains Solve
Without toolchains, Gradle compiles and tests with the JDK it is running on, which is whatever JAVA_HOME points to on that machine. One developer has Java 21, another Java 25, CI has something else, and the bytecode, the available APIs and test behaviour differ. Setting sourceCompatibility helps only partly, because it does not stop us from using APIs of the newer JDK.
A toolchain declares the Java version the build needs. Gradle then compiles, runs tests and runs JavaExec tasks with a JDK of that version, found among installed JDKs or downloaded if a resolver is configured, regardless of which JDK runs Gradle itself.
Notice the split. The JDK running Gradle only needs to be one that the Gradle version supports. The JDK for our code is chosen by the build, so every machine compiles and tests with the same version. IDEs read the toolchain from the imported model too: IntelliJ sets the module's language level and, when delegating, Gradle uses the toolchain JDK for runs and tests.
5Keeping Generated IDE Files Out of Version Control
Because the IDE builds its configuration from the Gradle model, its own files are derived data: the .idea directory and .iml files for IntelliJ, .project, .classpath and .settings for Eclipse. Committing them creates two sources of truth that drift apart. One developer's IDE version or local paths end up in commits, and a dependency added to the build but not to the committed IDE files confuses whoever opens the project next.
So the rule is that the build is the source of truth, and IDE files go into .gitignore. A fresh clone is opened in the IDE and imported from Gradle. A few shared, non-derived settings, such as a code style file, can still be committed deliberately, but nothing that describes modules or dependencies.
6Follow-up questions
Why does IntelliJ show red imports after I added a dependency?
The IDE's copy of the model is out of date. Reloading the Gradle project, from the prompt or the Gradle tool window, asks Gradle for a new model with the new dependency. If it still fails, the build itself may not resolve the dependency, which ./gradlew dependencies would also show.
What is the difference between toolchains and sourceCompatibility?
sourceCompatibility and the release flag control which language level and target bytecode javac produces, but with the current JDK. A toolchain chooses the JDK itself, so the compiler, the standard library APIs and the test JVM all match the declared version. With a toolchain, Gradle also sets the release level to match by default.
Does the IDE use the Gradle wrapper version?
Yes, by default IntelliJ IDEA and Buildship use the wrapper defined in the project, so the IDE configures the build with the same Gradle version as the command line and CI. Both can be set to use another installation, but that removes the consistency the wrapper gives.
7Conclusion
In this answer, we saw that IDEs import a Gradle build through the Tooling API, letting Gradle configure the build and creating their modules and dependencies from its model, so the build stays the source of truth. IntelliJ IDEA can delegate build and run to Gradle, which is most consistent with CI, or use its own compiler, and Eclipse integrates through Buildship. Java toolchains, declared with java { toolchain { languageVersion = JavaLanguageVersion.of(25) } }, choose the JDK used to compile and test, downloading it through a resolver if configured, and generated IDE files stay out of version control.
Open with
Both IDEs integrate through Gradle's Tooling API. When I open the project, IntelliJ starts Gradle with the project's wrapper version, Gradle runs the settings and build scripts, and returns a model of the build: projects, source sets, resolved dependencies, the Java version.
Then, if they want more
The IDE builds its modules from that model, so the Gradle build is the source of truth, and after editing a build file I reload the Gradle project to refresh it. In IntelliJ there is a setting for building and running: delegate to Gradle or use IntelliJ's own compiler.
I prefer delegating, because tests and runs then use the same tasks, generated sources, annotation processors and settings as CI; IntelliJ's own build can be faster but may skip custom tasks. Eclipse does the same import through the Buildship plugin. Toolchains solve a different problem: which JDK compiles and tests our code.
Without them it is whatever JAVA_HOME is on that machine. With java toolchain languageVersion set to 25, Gradle compiles and runs tests with a Java 25 JDK, finding an installed one or downloading it if a resolver like the foojay plugin is configured, while Gradle itself can run on another supported JDK.
Finally, I do not commit .idea, iml or Eclipse project files; they are generated from the build, and committing them creates a second source of truth.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 25
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Gradle user manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do IntelliJ IDEA and Eclipse integrate with a Gradle build, and what are Java...": https://scrivio-interview-library.netlify.app/java/gradle/a8b9a87ea1/