Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Intellij IDEA imports gradle project with old wrapper version?

I have a problem with gradle wrapper version in intellij idea. When I import a project it starts to download the old version of gradle and gradle wrapper

enter image description here

In my system variables I have gradle home which looks like this:

enter image description here

And in Path of system variables: enter image description here

My gradle build file looks like this:

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.3.41'
}

group 'com.epam.trykotlin'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

task wrapper(type: Wrapper) {
    gradleVersion = '5.6.4'
}

My gradle.xml in .idea folder looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        <option name="distributionType" value="DEFAULT_WRAPPED" />
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="gradleHome" value="C:/Gradle/gradle-5.6.4" />
        <option name="gradleJvm" value="11" />
        <option name="modules">
          <set>
            <option value="$PROJECT_DIR$" />
          </set>
        </option>
        <option name="useQualifiedModuleNames" value="true" />
      </GradleProjectSettings>
    </option>
  </component>
</project>

I've already tried to remove .gradle folder and .IdeaIC2019.2 folder but I've got the same problem. Why is it happened? How it can be fixed? I've also tried to reinstall IDE and it installs gradle plugin with 5.2.1 version. Why?

like image 671
Mefisto_Fell Avatar asked Sep 17 '25 09:09

Mefisto_Fell


1 Answers

In your particular use-case, you could probably first - outside of IntelliJ - run gradle wrapper in a terminal window in order for Gradle to setup the wrapper for the project using the version specified in your build file.

However, it seems like IntelliJ is hardcoded to download a Gradle wrapper 5.2.1 for all new projects and for all opened projects that haven't previously been configured any differently.

There doesn't seem to be any way of disabling this very odd behavior. This is sad, and almost beyond belief. Not only will this steal the user's Internet bandwidth and disk space, but it also causes major confusion and time-waste when the developer proceeds to debug his project setup and scratch his head why on earth this is happening.

I didn't stick around long enough to figure out if IntelliJ goes so far as to use an old version of Gradle that he downloaded instead of using the latest Gradle version I already have installed. Of course, it really wouldn't surprise me.

So the answer to your question why must be "a poorly designed Gradle plugin by self-proclaimed developers who long since forgot who they are working for".

The first thing we need to do though is to stop the extremely annoying download.

But, - and I kid you not - aborting the download I could only successfully do if I completed every single step in the following very onerous process. Cheating out on anyone of these steps didn't stop the download. Even though many of these steps don't seem to have an effect on the surface, every step did have an undisclosed side-effect that eventually contributed to the successful death of the download.

  • When you first create or open the project, there's a popup that kindly reveals that IntelliJ is downloading random binaries to unknown locations on your machine for unknown reasons. Click "cancel". The cancel button will be grayed out but of course, nothing is canceled.
  • Click on "background". This will close the popup window.
  • Click on the square and red "stop" button at the bottom left corner. Of course, this doesn't stop anything.
  • Click in the top menu; "File - Close project". This closes the main application window and we're back to a small window that now lists our project on the left side.
  • Close this window. IntelliJ will kindly popup a snark remark: "You have background tasks running. Are you sure you want to stop them and exit IntelliJ IDEA?"
  • Click "Exit" on this popup.

Then, we need to remove crap IntelliJ put on our disk. On my machine:

rm -r ~/.gradle/wrapper/dists/gradle-5.2.1-bin/

Now, we can open IntelliJ and go directly to our project without starting any Gradle downloads.

However, I want IntelliJ to use the Gradle I have installed. So I open the project and use the menu to open "File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle". In there I do the following:

  • Build and run using: Gradle
  • Run tests using: Gradle
  • Use Gradle from: Specified location /usr/lib/gradle/default

Of course all of the above must be repeated for every new project we wish to create and/or open.

like image 121
Martin Andersson Avatar answered Sep 21 '25 03:09

Martin Andersson