Why is Gradle Crying "Deprecated Features" and What to Do About It?
\n\nHave you ever launched a Kotlin project build and seen a frightening message: Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0? If so, you are not alone. This question has gathered thousands of views on Stack Overflow, and today we will analyze it inside and out.
Imagine: you are writing in Kotlin, everything works, but Gradle suddenly starts being fussy. It says: "Hey, you are using old features that I will remove in version 5.0!". It's like your favorite coffee machine telling you that tomorrow it will stop accepting old cups. Unpleasant, but solvable.
\n\nIn this article, we will not just show how to remove the error. We will compare three approaches to the solution: from a quick "patch" to professional refactoring. You will learn why Gradle considers your code deprecated and how to rewrite it in a modern way.
\n\nWhat are Deprecated Features in Gradle?
\n\nDeprecated features are those parts of the API that the Gradle developers plan to remove in the future. They are left for backward compatibility, but it is no longer recommended to use them. When you see this warning, Gradle is literally saying: "Your project will build now, but after updating to version 5.0 — it won't."
\n\nMost often, the problem lies in:
\n- \n
- Outdated plugins (e.g., old versions of
kotlin-gradle-plugin) \n - Implicit dependencies (using
compileinstead ofimplementation) \n - Groovy scripts that are not adapted for Kotlin DSL \n
- Direct calls to deprecated methods in
build.gradle\n
Approach 1: Quick Fix — Suppressing Warnings
\n\nThe simplest (but not the most correct) path is to just tell Gradle: "Shut up and work." It's like taping over the Check Engine light with duct tape. The car will drive, but the problems remain.
\n\nAdd the following block to build.gradle.kts (Kotlin DSL):
tasks.withType<Wrapper> {\n gradleVersion = "4.10.3" // freezing the version\n}\n\n// Or suppressing the warning\nallprojects {\n tasks.withType<AbstractCompile> {\n options.isDeprecation = false\n }\n}\n\nPros: fast, requires no code changes, the build passes.
\nCons: you are not solving the problem, just postponing it. When migrating to Gradle 5.0+, the project will break. Additionally, you miss important performance and security improvements.
\n\nWhen to use: only if you urgently need to build the project and have no time for refactoring. But be sure to schedule a proper solution.
\n\nApproach 2: Migration to Modern Configurations
\n\nThis is the "sweet spot." You are not just plugging the error, but putting the project in order. Let's break down typical problems using a Kotlin project as an example.
\n\nReplacing compile with implementation/api
\n\nThe old way of declaring dependencies — compile — was deprecated back in Gradle 3.0. Instead, use implementation and api.
Was (Groovy):
\ndependencies {\n compile 'org.jetbrains.kotlin:kotlin-stdlib:1.3.72'\n compile 'com.squareup.retrofit2:retrofit:2.9.0'\n}\n\nNow (Kotlin DSL):
\ndependencies {\n implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.0")\n implementation("com.squareup.retrofit2:retrofit:2.9.0")\n}\n\nThe difference is simple: implementation hides the dependency from module consumers, speeding up the build. api makes it visible, like the old compile.
Updating the Kotlin Plugin
\n\nOld versions of kotlin-gradle-plugin often use deprecated Gradle API. Check the current version on kotlinlang.org and update