Kotlin plugin error: Could not generate a proxy class for class org.jetbrains.kotlin.gradle.tasks.KotlinCompile

10,260

Solution 1

starting kotlin 1.1.2 JDK below 1.8 is not supported anymore by the kotlin compiler as in 1.1.2 blog post:

The Kotlin compiler now requires JDK 8 to run. You shouldn’t notice any changes, because most other Java development tools such as Gradle and the Android toolchain also require JDK 8, so you almost certainly already have it installed. For code generated by the compiler, Java 1.6 compatibility is still the default, and we have no plans to drop support for generating Java 1.6 compatible bytecode.

Solution 2

In my case, it was because I was running gradle with java 1.7 and it looks like the plugin was compiled only for 1.8:

16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'kotlin']
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:153)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:112)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyType(DefaultObjectConfigurationAction.java:113)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:80)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:136)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:46)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.java:34)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.Script$apply$1.callCurrent(Unknown Source)
16:48:42.742 [ERROR] [org.gradle.BuildExceptionReporter]        at build_4u37tyfuy0k7d4zd8vsk5lx9d.run(build.gradle:17)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        ... 63 more
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.GradleException: Could not generate a proxy class for class org.jetbrains.kotlin.gradle.tasks.KotlinCompile.
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.AbstractClassGenerator.generateUnderLock(AbstractClassGenerator.java:201)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.AbstractClassGenerator.generate(AbstractClassGenerator.java:64)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.project.taskfactory.TaskFactory.create(TaskFactory.java:115)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.project.taskfactory.TaskFactory.createTask(TaskFactory.java:77)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.createTask(AnnotationProcessingTaskFactory.java:101)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.project.taskfactory.DependencyAutoWireTaskFactory.createTask(DependencyAutoWireTaskFactory.java:39)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:62)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:97)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider.createKotlinJVMTask(TasksProvider.kt:26)
16:48:42.743 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.Kotlin2JvmSourceSetProcessor.doCreateTask(KotlinPlugin.kt:111)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.Kotlin2JvmSourceSetProcessor.doCreateTask(KotlinPlugin.kt:93)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor.createKotlinCompileTask(KotlinPlugin.kt:83)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor.<init>(KotlinPlugin.kt:56)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.Kotlin2JvmSourceSetProcessor.<init>(KotlinPlugin.kt:101)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.KotlinPlugin.buildSourceSetProcessor$kotlin_gradle_plugin_main(KotlinPlugin.kt:302)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.KotlinPlugin.buildSourceSetProcessor$kotlin_gradle_plugin_main(KotlinPlugin.kt:295)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.AbstractKotlinPlugin$configureSourceSetDefaults$1.execute(KotlinPlugin.kt:279)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.AbstractKotlinPlugin$configureSourceSetDefaults$1.execute(KotlinPlugin.kt:256)
16:48:42.744 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:110)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.AbstractKotlinPlugin.configureSourceSetDefaults(KotlinPlugin.kt:278)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.AbstractKotlinPlugin.apply(KotlinPlugin.kt:269)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.KotlinPlugin.apply(KotlinPlugin.kt:306)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.KotlinPlugin.apply(KotlinPlugin.kt:295)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper.apply(KotlinPluginWrapper.kt:46)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper.apply(KotlinPluginWrapper.kt:34)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:43)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:137)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        ... 73 more
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.UnsupportedClassVersionError: org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments : Unsupported major.minor version 52.0
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.internal.reflect.ClassInspector.inspectClass(ClassInspector.java:67)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.internal.reflect.ClassInspector.visitGraph(ClassInspector.java:51)
16:48:42.745 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.internal.reflect.ClassInspector.inspect(ClassInspector.java:31)
16:48:42.746 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.AbstractClassGenerator.inspectType(AbstractClassGenerator.java:260)
16:48:42.746 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.AbstractClassGenerator.inspectType(AbstractClassGenerator.java:216)
16:48:42.746 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.AbstractClassGenerator.generateUnderLock(AbstractClassGenerator.java:95)

Related tickets: https://youtrack.jetbrains.com/issue/KT-17866 and https://youtrack.jetbrains.com/issue/KT-17297

Solution 3

If you're still receiving this error despite:

  • Setting the JAVA_HOME environment variable to your JDK8 installation.
  • Changing sourceCompatibility in your build.gradle file.
  • Pointing to JDK8 in your gradle.properties file.

It's possible that you're running an old version of gradle.

I was receiving this error on gradle version 3.2, but upgrading to version 5.1 fixed the error for me.

You can download the latest release from Gradle's Website.

More info here.

Share:
10,260

Related videos on Youtube

Philipp Grigoryev
Author by

Philipp Grigoryev

Updated on September 15, 2022

Comments

  • Philipp Grigoryev
    Philipp Grigoryev about 1 year

    Getting an error while trying to run a gradle task. Can't figure out what else is required or what the error is about. The project I'm working on has several subprojects, so I have a main build.gradle. The error is for a subproject where I wanted to try Kotlin.

    * Where: Build file '/home/oracle/bnc/KotlinHandler/build.gradle' line: 13
    
    * What went wrong: A problem occurred evaluating root project 'KotlinHandler'.
    > Failed to apply plugin [id 'kotlin']
       > Could not generate a proxy class for class org.jetbrains.kotlin.gradle.tasks.KotlinCompile.
    

    Here is my build.gradle for the failing module (sub-project).

    buildscript {
        ext.kotlin_version = '1.1.2-2'
    
        repositories {
            mavenCentral()
        }
    
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    apply plugin: 'kotlin'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    }
    

    Here is Pastebin build.gradle which is quite big, because of all the tasks in it

    Added --debug output after changing jdk to 1.8 and compile dependency to compile "org.jetbrains.kotlin:kotlin-stdlib-jre8

  • MakerDrone
    MakerDrone over 6 years
    I had the same problem. Installing oracle-java8 and setting gradle to run with java 1.8 solved it for me. Thank you @DanielSilva
  • Philipp Grigoryev
    Philipp Grigoryev over 6 years
    Thank you @oshai, i figured that. Unfortunately i have to deal with jdk7 as it's the target jvm version
  • oshai
    oshai over 6 years
    Its not totally related and you can see it in the blog post: when you compile you need at least JDK 8, but you can target bytecode to be in other language level such as 1.7. for example in gradle you will add the directive: sourceCompatibility = 1.6
  • Philipp Grigoryev
    Philipp Grigoryev over 6 years
    Yeah, you are right. I specified a path to JDK8 and it started working. Thank you!
  • Philipp Grigoryev
    Philipp Grigoryev over 6 years
    Had to specify jdk8 path in gradle.properties and it started working
  • Philipp Grigoryev
    Philipp Grigoryev over 6 years
    Yup, jdk8 specified in gradle.properties helped
  • oshai
    oshai over 6 years
    You are welcome. I recommend that you accept it as the answer to help others.
  • Philippe
    Philippe almost 6 years
    Make sure gradle runs with the right JDK. In my case there are multiple JDKs on the box, so I ended up telling gradle which one to use as follows: gradlew :myTask -Dorg.gradle.java.home=/usr/lib/jvm/jre-1.8.0
  • Philippe
    Philippe almost 6 years
    Or you can specify on the command line: gradlew :myTask -Dorg.gradle.java.home=/usr/lib/jvm/jre-1.8.0
  • J Horseman
    J Horseman over 4 years
    Thanks man, you saved my ass. Normally I am working with close-to-latest versions, but I had this weird setup which specifically downloaded an old version without me noticing... Already cost me hours...
  • byxor
    byxor over 4 years
    @JHorseman Glad I could help. I also wasted a lot of time with this.