IntelliJ successfully syncs even if there is build error on Gradle 4.7 but not on 4.8+

Answered

To reproduce:
I am using the latest IntelliJ IDEA, 2021.1, Community Edition. My Gradle settings inside IDEA:
Build and run using: Gradle
Run tests using: Gradle
Use Gradle from: ‘gradle-wrapper.properties’ file
Gradle JVM: 1.8 version 1.8.0_282

I create a new directory with the following build.gradle file:

gradle.taskGraph.whenReady {
throw new GradleException(“foo”)
}

and the following gradle/wrapper/gradle-wrapper.properties file:

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

IntelliJ IDEA loads and syncs the project with no errors, with the message:

CONFIGURE SUCCESSFUL in 2s

(Although running any Gradle task will still produce an error.) However, when I change the Gradle version to 4.8 (or any higher version):

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

and then close the project, delete the .gradle and .idea directories, and reopen the project in IntelliJ IDEA, IntelliJ IDEA fails to sync, with the error:

Build file ‘/home/username/path_to_project/build.gradle’ line: 2
foo

My question is, what caused the change in behavior in syncing between Gradle versions 4.7 and 4.8? And what can I do to bring back the behavior where it successfully syncs even if build fails, on Gradle versions 4.8 and above?

I don't even know where to start debugging this. How can I find out what Gradle commands IntelliJ runs when it syncs a project?

0
1 comment

Starting with the Gradle 4.8 version there were changes in Gradle Tooling API (which IDE uses for managing Gradle builds) for Gradle project model and tasks which now now triggers the tasks graph invocation which leads to this error. The change has been done in scope of this issue https://github.com/gradle/gradle/pull/4533 This is expected behavior.

0

Please sign in to leave a comment.