Why Gradle downloads “Android plugin” again for newly cloned projects

I use Gradle 4.9 and Android Studio 3.1.4 and used 'com.android.tools.build:gradle:3.3.0-alpha05' as classpath dependency in previously builded project also I can see directories with name 3.3.0-alpha05 in ~/.gradle/caches/. So when I create a new project, Android Studio sets that version for as classpath dependency in build.gradle.

But when I clone a project from GitHub, which uses older version of Gradle and Android plugin and change version of Gradle and Android plugin for Gradle to match latest used versions in previously builded projects and try to do sync project with gradle files then Android Studio says:

No cached version of com.android.tools.build:gradle:3.3.0-alpha05
available for offline mode.

Disable Gradle ‘offline mode’ and sync
project

For example XRefreshView is set to use com.android.tools.build:gradle:2.1.0 and gradle-2.10 and when I changed settings and tried to sync, I got above error.

Why Gradle tries to download that downloaded/cached plugin again?

Depending on what versions of Gradle you’re switching between, the format of the cache directory may have changed. This means Gradle would need to re-download the plugin in order to store it in the different format. I do not believe Gradle makes any effort to re-use old cache formats, it simple uses the format it understands.

It doesn’t redownload the plugin, only its metadata (pom.xml).

@Chris_Dore I did not change version of installed Gradle, I change the version of Gradle which is used by project. So there is no change in structure of cache directory.

@st_oehme How I can sure it only downloads the pom.xml? Also as I described, I did not change the version of installed Gradle and thus structure of cache directory. So why it tries to download again?

It doesn’t matter what you have installed somewhere on your system. What matters is which version your project uses.

@st_oehme Do you mean if I change distributionUrl=https://services.gradle.org/distributions/gradle-4.9-all.zip of <path to project>/gradle/wrapper/gradle-wrapper.properties to point to another version of Gradle, then it will change structure of cache directory in ~/.gradle/caches/?

It will use a different directory for each version of our internal metadata format. It doesn’t “change” any existing data, it creates new data.