Kotlin gradle Could not initialize class class org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt

JavascriptGradleKotlin

Javascript Problem Overview


I tried to use gradle for transpiling Kotlin to Js. When I run the example from https://www.codeflow.site/fr/article/kotlin-javascript I got the error : Could not initialize class org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt which comes from line apply plugin: 'kotlin2js' of build.gradle.

I have no idea of what the missing class is and why kotlin2js is asking for it. Any suggestion ?

Javascript Solutions


Solution 1 - Javascript

Solved this issue by setting the latest Kotlin version (1.3.72) in build.gradle file.

buildscript {
ext {
    kotlinVersion = '1.4.20'
    springBootVersion = '2.0.4.RELEASE'
}
repositories {
    mavenCentral()
}
... 
}

Solution 2 - Javascript

I just had the same issue. On windows, I checked the kotlin version from the command line with gradle -v and then adjusted the kotlin version in build.gradle of my project to match my version of gradle.

I hope this works for you too.

Solution 3 - Javascript

In my case this solves the problem:

buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        
    }
}

Set ext.kotlin_version = "1.3.72" and $kotlin_version

Solution 4 - Javascript

Yes, as many before have said, the problem is probably that you have a kotlin version mis-match. But how do you know what version of kotlin is installed?

To find out your version of kotlin: Settings -> Language & Frameworks -> Kotlin

picture of settings

Make sure that you change your kotlin version (in both build.gradle files!) to this exact number. In my case (above) it's 1.4.10

Good luck!

Solution 5 - Javascript

In Android Studio: File -> Project Structure -> Variables

There edit the kotlin_version to e.g. 1.3.72

Gradle should resync automatically, otherwise resync manually

Solution 6 - Javascript

update your Version in your gradle.properties file. eg) kotlinVersion=1.3.72

Solution 7 - Javascript

Simplest solution:

Go to file -> project structure (ctrl+shift+alt+s) -> suggestions -> accept all the suggestions.

To answer the OP's quetion, you just need to accept the one with the kotlin version

Solution 8 - Javascript

Solution 9 - Javascript

I don't know if I can do the same as KP7984 said - to check the versions of the plugins of my Android Studio, not the ones of my OS. I use gradlew -v of my project instead of gradle -v and it works for me.

Solution 10 - Javascript

In your build.gradle file if you hover over the classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" it will tell you what version of Kotlin you will have to use in the kotlinVersion variable at the top of the file, according to your SDK/plugins versions.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEmile AchaddeView Question on Stackoverflow
Solution 1 - JavascriptLiebster KameradView Answer on Stackoverflow
Solution 2 - JavascriptKP7984View Answer on Stackoverflow
Solution 3 - JavascriptCarlos ChaguendoView Answer on Stackoverflow
Solution 4 - JavascriptSMBiggsView Answer on Stackoverflow
Solution 5 - JavascriptMatthias KuhnView Answer on Stackoverflow
Solution 6 - JavascriptAngelaGView Answer on Stackoverflow
Solution 7 - JavascriptMehul PamaleView Answer on Stackoverflow
Solution 8 - JavascriptJim CView Answer on Stackoverflow
Solution 9 - JavascriptStndFishView Answer on Stackoverflow
Solution 10 - JavascriptAlexandru TopalăView Answer on Stackoverflow