Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle 6 with Intellij - refresh fails

I have a gradle 6.0 project with Spring 2.1.7.

When I try to refresh all gradle projects from intellij enter image description here

I got an error:

Unable to load class 'org.gradle.api.internal.plugins.DefaultConvention'. Possible causes for this unexpected error include:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

I use intellij v 2018.3.4 and I've configured it to use the gradle wrapper:

enter image description here

The gradle-wrapper.properties looks like this:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

If I run the gradle wrapper from command line there are not problems. Also If I trigger a gradle task (build, clean ...) from Intellij I have no errors.

I have another wired issue that could be related to this one. In my build.gradle I use spring boot 2.1.7 and If I run my jar from the command line I can see from the Spring Boot banner the configured version 2.1.7. Instead If I run the application form Intellij I see that It is using Spring Boot 2.0.8, also if I expand the External libraries tree I see: enter image description here

the build.gradle looks like:

buildscript {
 ext {
   springBootVersion = "2.1.7.RELEASE"
   springBootDepManagementVersion = "1.0.8.RELEASE"
 }
}
plugins {
 id 'idea'
 id 'java'
 id "io.spring.dependency-management" version "${springBootDepManagementVersion}"
 id 'org.springframework.boot' version "${springBootVersion}"
}
dependencies {
   implementation 'org.springframework.boot:spring-boot-starter-web'
   ....
}

Thank you

like image 507
Fabry Avatar asked Nov 19 '19 09:11

Fabry


People also ask

How do I run Gradle refresh in IntelliJ?

We can do this by: Selecting one of the suggestions in the message; Pressing on the Refresh Gradle icon in the top right, Using the keyboard shortcut ⇧⌘I (macOS), or Ctrl+Shift+O (Windows/Linux).

How do I fix Gradle sync issues in IntelliJ?

We can configure the settings for how IntelliJ IDEA syncs with Gradle by pressing the settings icon in the Gradle tool window, and selecting Auto-Reload Settings. We can set IntelliJ IDEA to automatically reload the project after "Any changes" in the build script files, so changes are automatically reloaded.

Why is my Gradle build failing?

In some cases when your Gradle files are deleted or corrupted you will not be able to download new Gradle files in android studio. In this case, we have to delete the Gradle files which are present already and then again sync your project to download our Gradle files again.


2 Answers

I solved the problem downgrading the gradle wrapper to 5.6.4. Apparently my Intellij version does not support gradle 6.0.0

like image 141
Fabry Avatar answered Sep 30 '22 10:09

Fabry


Downgrading also do the job for me:

gradlew wrapper --gradle-version 5.6.4
like image 36
Xelian Avatar answered Sep 30 '22 10:09

Xelian