Quick revision
The short answer
I would treat build logic as production code: kept in a small number of versioned, reviewed and tested convention plugins, with project build scripts that only declare what the project is. I would stay on public, non-deprecated Gradle APIs, upgrade the wrapper regularly, keep every build compatible with the configuration cache, and write down the conventions so the next team can follow them without reverse-engineering the scripts.
What to remember
In this answer, we saw how build code decays when it is copied, clever and left behind on old Gradle versions. The principles that prevent it are to treat build logic as production code in a few tested convention plugins, keep project scripts declarative, use only public and non-deprecated Gradle APIs, upgrade the wrapper regularly, keep the build compatible with the configuration cache, and document the conventions so people who did not write them can maintain them.
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.
I would treat build logic as production code: kept in a small number of versioned, reviewed and tested convention plugins, with project build scripts that only declare what the project is. I would stay on public, non-deprecated Gradle APIs, upgrade the wrapper regularly, keep every build compatible with the configuration cache, and write down the conventions so the next team can follow them without reverse-engineering the scripts.
Why this question is asked
Build scripts outlive the people who write them. A service written today may still be built in ten years by engineers who never met its authors, on a Gradle version that does not exist yet. Most build pain in old codebases comes from clever one-off scripts, copied blocks that drifted apart, and APIs that Gradle removed years ago. Interviewers ask this at the senior level to hear whether we think about the cost of build code over its whole life, not just whether it works today. In this answer, we will look at how build code decays, then walk through the principles I would set, why each one matters, and what it costs.
1How Build Code Decays Over Ten Years
Picture a company with 40 services. In year one, each service has a build.gradle.kts of about 60 lines, copied from the first service and tweaked. By year five, those 40 copies have drifted: some pin an old Checkstyle version, some disabled a test task during an incident and never turned it back on, some read a system property in a way that breaks caching. Nobody knows which differences are intentional.
Then comes a Gradle major upgrade. Each major version removes APIs that were deprecated in the previous one. A team that ignored deprecation warnings for three years now faces dozens of failures across 40 builds, each slightly different. This is the typical path: not one big mistake, but many small choices that each made sense locally and together make the build unmaintainable.
2Principle 1: Build Logic Is Production Code
The first rule is that build logic lives in convention plugins, not in copied script blocks. A convention plugin is a small Gradle plugin, usually written as a Kotlin script in a build-logic build or a shared repository, that applies the organisation's standard settings: the Java toolchain, test configuration, static analysis, publishing. Each project applies it with one line.
Because it is code, it gets what production code gets: it is versioned, changes go through review, and it has tests. Gradle's TestKit lets us run a small sample build against the plugin in a unit test and check that, for example, tests use JUnit Platform and Checkstyle fails on a violation. A change that would break 40 builds then fails one test instead.
- Project build scriptsdeclare plugins and dependencies only
- Convention pluginstoolchain, tests, checks, publishing; versioned and tested
- Version catalog and platformdependency versions in one place
- Gradle and its public APIsupgraded regularly through the wrapper
4 layers, from the top down. Step through them one at a time.
The higher a layer, the less logic it should contain.
Notice how little is left in the project script. That is the second rule in action: project scripts are declarative, and imperative logic, meaning loops, conditions and custom tasks, belongs in plugins where it is written once and tested. A new engineer reading this file understands it in ten seconds.
3Principle 2: Stay on Public APIs and Stay Current
Gradle has public APIs, documented and covered by its deprecation policy, and internal ones, in packages with internal in their name, which can change in any release. Build code that reaches into internal classes or keeps using deprecated APIs works today and breaks on an upgrade. So the rule is: no internal APIs, and deprecation warnings are treated as defects. Running builds in CI with --warning-mode fail turns a deprecation into a failed build while the fix is still small.
The second half is upgrading the wrapper often, for example within a quarter of each minor release. Upgrading from one minor version to the next is usually a ten-minute change. Skipping three years means reading several upgrade guides at once and fixing everything together. Staying close to the current version also keeps the build on a Gradle that supports the current JDK, which matters because each Gradle release has a newest Java version it can run on.
4Principle 3: Keep the Build Configuration-Cache Compatible
The configuration cache stores the result of the configuration phase, the graph of configured tasks, and reuses it when the build scripts and their inputs have not changed. On a large build this can save tens of seconds on every invocation. It is also the direction Gradle is moving in: features such as project isolation build on the same rules.
Those rules are strict but simple. Tasks must not touch the Project object while they run, must read environment variables and system properties through providers, and must declare their inputs. A build that follows them stays fast as it grows and keeps working as Gradle tightens these rules. A build that ignores them collects incompatibilities that someone will have to fix under pressure later. So I would enable the configuration cache in gradle.properties from day one, when fixing problems is cheap.
5Principle 4: Few Plugins, Written Down
Every custom plugin is something the future team must understand. So I would keep their number small, perhaps three or four convention plugins such as java-library, spring-service and published-library, rather than a plugin for every small variation. When a team asks for a new one, the first question is whether a setting in an existing plugin would do.
Then the conventions are written down: a short document in the build-logic repository that says which plugin to use for which kind of project, what each one configures, how to override a setting, and how to release a new version of the plugins. Ten years from now the authors will be gone, and this document, plus the tests, is what explains the intent behind the code.
| Principle | What it prevents | Cost today |
|---|---|---|
| Convention plugins, tested | 40 drifting copies of the same block | A build-logic repo and TestKit tests |
| Declarative project scripts | Logic nobody can find or test | Discipline in review |
| Public APIs, warnings fail CI | A painful upgrade after years | Small fixes as deprecations appear |
| Regular wrapper upgrades | Falling behind Gradle and JDK support | A routine task each quarter |
| Configuration cache from day one | Slow builds, blocked future features | Using providers and declared inputs |
| Few plugins, documented | Knowledge lost when authors leave | Saying no to one-off plugins |
6Follow-up questions
Why not just keep a shared subprojects block in the root build script?
Cross-project configuration with subprojects or allprojects makes every project depend on the root script, hides where a setting comes from, and works against the configuration cache and project isolation, because one project's script is reaching into others. A convention plugin is applied explicitly by each project, so the configuration is visible where it is used and each project is configured independently.
How do you test a convention plugin?
With Gradle TestKit. The test writes a tiny build into a temporary directory that applies the plugin, runs it with GradleRunner, and checks the outcome, for example that the build fails when a test fails, or that the jar manifest has the expected entries. We can also run the same test against several Gradle versions to catch compatibility problems before an upgrade.
What do you do with an old build that breaks every one of these rules?
I do not rewrite it in one go. I move its repeated blocks into the existing convention plugins one at a time, turn on --warning-mode all to list deprecations, and fix the ones that block the next upgrade first. Each step is a small reviewed change that keeps the build green.
7Conclusion
In this answer, we saw how build code decays when it is copied, clever and left behind on old Gradle versions. The principles that prevent it are to treat build logic as production code in a few tested convention plugins, keep project scripts declarative, use only public and non-deprecated Gradle APIs, upgrade the wrapper regularly, keep the build compatible with the configuration cache, and document the conventions so people who did not write them can maintain them.
Open with
I would assume the people maintaining the build in ten years will know only what the code and a short document tell them. So first, build logic is production code.
Then, if they want more
It lives in a small number of convention plugins, for example one for libraries and one for Spring services, in a build-logic repository, and it is versioned, reviewed and tested with TestKit. Project build scripts stay declarative: they apply one plugin and list dependencies, with no loops or custom tasks.
Second, we use only public Gradle APIs and treat deprecation warnings as defects; CI runs with warning mode fail, so a deprecation is fixed when it is small, and we upgrade the wrapper every quarter or so rather than jumping three majors at once.
Third, every build is configuration-cache compatible from the start, which means tasks use providers and declared inputs and never touch the project at execution time. That keeps builds fast and ready for where Gradle is going. Fourth, I keep the number of custom plugins small and write down what each one does and how to change it.
The cost is some discipline now, but it turns a future upgrade from a project into a routine change.
About this answer
- Last updated
- 12 November 2026
- 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 "Ten years from now your build scripts will be maintained by people who did not write...": https://scrivio-interview-library.netlify.app/java/gradle/b52d48fd4d/