When switching to Kotlin >=1.5.20 then failure 'e.project.sync.GradleSyncState - Unable to load class 'org.antlr.v4.runtime.Lexer occurs'

When using Kotlin <=15.10 everything works as expected. Then I switch to Kotlin 1.5.20. During reloading of gradle project following error occurs in the event log:

This is an unexpected error. Please file a bug containing the idea.log file.
com.intellij.openapi.externalSystem.model.ExternalSystemException: Unable to load class ‘org.antlr.v4.runtime.Lexer’

In the log file:

Caused by: java.lang.ClassNotFoundException: org.antlr.v4.runtime.Lexer
… 191 more
2021-07-19 22:19:13,422 [2633503] WARN - ues.SyncIssueUsageReporterImpl - Multiple sync failures reported. Discarding: SDK_BUILD_TOOLS_TOO_LOW
2021-07-19 22:19:13,423 [2633504] WARN - ues.SyncIssueUsageReporterImpl - Multiple sync failures reported. Discarding: SDK_BUILD_TOOLS_TOO_LOW
2021-07-19 22:19:13,431 [2633512] WARN - e.project.sync.GradleSyncState - Gradle sync failed: Unable to load class ‘org.antlr.v4.runtime.Lexer’.

This is an unexpected error. Please file a bug containing the idea.log file. (5 s 686 ms)
2021-07-19 22:19:13,432 [2633513] WARN - e.project.sync.GradleSyncState - Unable to load class ‘org.antlr.v4.runtime.Lexer’.

This is an unexpected error. Please file a bug containing the idea.log file.
com.intellij.openapi.externalSystem.model.ExternalSystemException: Unable to load class ‘org.antlr.v4.runtime.Lexer’.

What could it be, that with change of the Kotlin version suddenly such a problem occurs?

Looks like https://youtrack.jetbrains.com/issue/KT-47098

It looks like you are hitting the same issue I had, try to fetch the kotlin plugin from mavenCentral() instead of maven("https://plugins.gradle.org/m2/"), it might help.

The POM coming from the gradle repo is wrong for some reason.

Not exactly, https://youtrack.jetbrains.com/issue/KT-47098 is a multiplatformproject, mine is a JS project. And for JS the problems start with 1.5.20.

1.5.0 and 1.5.10 is OK so far for JS

There is mentioned that there seem to be problems with generateExternals = true. And indeed, when I comment out the lines, where externals are generated and replace with a version without generating externals, then it works. Thus it seem to go in that direction. My dependencies block is now looking like that:

dependencies {
testImplementation(kotlin(“test-js”))
implementation(“org.jetbrains.kotlinx:kotlinx-html-js:0.7.2”)
implementation(“org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3”)
implementation(“org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2”)
implementation(“org.jetbrains.kotlinx:kotlinx-datetime:0.2.1”)
//implementation(npm(“jquery”, “3.5.1”, generateExternals = true))
implementation(npm(“jquery”, “3.5.1”))
implementation(npm(“popper.js”, “^1.16.1”))
//implementation(npm(“bootstrap”, “4.5.3”, generateExternals = true))
implementation(npm(“bootstrap”, “4.5.3”))
}

I don’t even find a place, where maven("https://plugins.gradle.org/m2/") is set. Do you mean the repositories block in the build.gradle.kts or do you mean any property digged in the settings. My repositories block looks like this

repositories {
jcenter()
mavenCentral()
maven { url = uri(“https://dl.bintray.com/kotlin/kotlinx”) }
}

so far.

Plugins use the gradle repo by default and do not use the same repo as the regular dependencies
There is a documentation on how to customize plugin resolution, this is where you want to put mavenCentral() first and maven("https://plugins.gradle.org/m2/") second so maven central has priority.

Yes indeed - that solved the problem. Strange thing. Thanks, mate!