Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

kotlin-compiler-embeddable version clash when applying kotlin-gradle-plugin via buildSrc #1207

Closed
kris7t opened this issue Oct 25, 2018 · 7 comments

Comments

@kris7t
Copy link

kris7t commented Oct 25, 2018

There seem to be a clash between dependencies of the kotlin-compiler-embeddable used to compile the buildSrc module and the kotlin-gradle-plugin used in the rest of the build when I try to apply or configure the plugin from another plugin placed in buildSrc. As I have to add kotlin-gradle-plugin to the classpath of buildSrc in this case (instead of applying in from the plugins block of the root project), transitive dependency resolution seems to select the incorrect version of kotlin-compiler-embeddable (1.2.61 instead of 1.2.71), leading to a build failure due to class incompatibility.

Expected Behavior

When adding kotlin-gradle-plugin as a dependency in the buildSrc module, the appropriate Kotlin compiler should be present in the classpath of the rest of the build (as if kotlin-gradle-plugin was applied as a plugin in the root project, with explicitly specified version).

Current Behavior

When trying to write a plugin inside buildSrc that applies kotlin-gradle-plugin:1.2.71, the build fails with the following exception:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':jani-model:compileKotlin'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
        at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.NoSuchMethodError: org.jetbrains.kotlin.incremental.BuildUtilKt.makeModuleFile(Ljava/lang/String;ZLjava/io/File;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/io/File;
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJvmCompiler(GradleKotlinCompilerRunner.kt:102)
        at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:393)
        at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:297)
        at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:259)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
        ... 31 more

The reason for this seems to be the incorrect version of kotlin-compiler-embeddable:

$ ../gradlew dependencyInsight --dependency org.jetbrains.kotlin:kotlin-compiler-embeddable 
> Task :dependencyInsight
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.2.61 (selected by rule)
   variant "runtime" [
      org.gradle.status = release (not requested)
      Requested attributes not found in the selected variant:
         org.gradle.usage  = java-api
   ]

org.jetbrains.kotlin:kotlin-compiler-embeddable:1.2.71 -> 1.2.61
+--- org.jetbrains.kotlin:kotlin-android-extensions:1.2.71
|    \--- org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71
|         \--- compileClasspath
+--- org.jetbrains.kotlin:kotlin-annotation-processing-gradle:1.2.71
|    \--- org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71 (*)
\--- org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71 (*)

(*) - dependencies omitted (listed previously)

It seems that the dependency used by the embedded Kotlin version (1.2.61) "leaks" from the kotlinCompiler configuration of buildSrc to the rest of the configurations.

There is no version clash if I apply the kotlin-gradle-plugin to the root project (with explicitly specified version). Of course, in this case it is impossible to add it to the buildSrc dependencies, since no version can be specified for plugins already on the build classpath. This prevents me from writing a custom plugin in buildSrc that configures the Kotlin compiler.

There is also no version clash if I downgrade to Kotlin 1.2.61 in the project.

As a workaround I can force the embeddable Kotlin compiler to 1.2.71 in the buildSrc as follows:

configurations.all {
    val isKotlinCompiler = name == "embeddedKotlin" || name.startsWith("kotlin") || name.startsWith("kapt")
    if (!isKotlinCompiler) {
        resolutionStrategy.eachDependency {
            if (requested.group == "org.jetbrains.kotlin" && requested.module.name == "kotlin-compiler-embeddable") {
                useVersion("1.2.71")
            }
        }
    }
}

Simply using force did not help, because the dependency version is apparently selected by rule. I presume I have to write another rule to override in this case.

Context

I'm trying to store common configuration across modules using plugins defined in buildSrc in a project where the modules, the buildSrc plugins, and the build scripts are all written in Kotlin.

As an example of such configuration, see https://github.com/FTSRG/theta-jani-interchange/blob/84cbe35d2e7b9661319fb450694099c770b9a656/buildSrc/src/main/kotlin/hu/bme/mit/inf/theta/interchange/jani/buildsrc/KotlinConventions.kt

Steps to Reproduce (for bugs)

  1. Use kotlin-dsl in buildSrc.
  2. Add compile(kotlin("gradle-plugin", "1.2.71")) to the buildSrc module dependencies
  3. Create a plugin in buildSrc that runs apply<KotlinPlatformJvmPlugin>() in its apply method
  4. Apply the plugin in a subproject containing Kotlin code
  5. Try to ./gradlew compileKotlin

Your Environment

Relevant versions:

  • Gradle 4.10.2
  • kotlin-dsl using Kotlin 1.2.61
  • the rest of the sources using Kotlin 1.2.71

Note that the build also contains the io.gitlab.arturbosch.detekt plugin, which is applied from the plugins block of the root project as usual. Even though it is written in Kotlin 1.2.61, it does not disturb the build when kotlin-gradle-plugin is also applied from the plugins block (and not buildSrc dependencies). This highlights that there is no clash of differing Kotlin versions, unless the clash involves buildSrc.

@eskatos
Copy link
Member

eskatos commented Nov 5, 2018

This is a breaking change in the kotlin-gradle-plugin between 1.2.6x (embedded in Gradle 4.10) and 1.2.7x. Can you try with Gradle 5.0-rc-1 that embedds Kotlin 1.3.0?

@kris7t
Copy link
Author

kris7t commented Nov 6, 2018

I there any way I can try forcing a specific Kotlin version on Gradle 5.0-rc-1? I mean, it already embeds 1.3.0, so I can't set anything newer (yet). Is building 1.2.7x projects with Gradle 5.0 supported, despite the embedded 1.3.0 compiler?

@eskatos eskatos modified the milestones: 1.1.0, 1.0.2 Nov 21, 2018
@eskatos
Copy link
Member

eskatos commented Nov 21, 2018

@kris7t we fixed this in #1241, you can try it out with Gradle 5.0-rc-4.

Also see the following new test that assert things are working from 1.2.20 to 1.3.10

https://github.com/gradle/kotlin-dsl/blob/9de61770891782887eb5a8828a5157dd2707f202/subprojects/plugins/src/test/kotlin/org/gradle/kotlin/dsl/plugins/dsl/KotlinDslPluginGradlePluginCrossVersionSmokeTest.kt#L42-L46

@eskatos eskatos closed this as completed Nov 21, 2018
@TomasKuhn
Copy link

Hi. I'm trying to update Kotlin version to 1.4.0-rc but it's not working. I have the same error as @kris7t.
It seems that BuildScr forces kotlin-compiler-embeddable to 1.3.72, so I can see the errors like:

e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.cli.common.messages.MessageCollector$DefaultImpls.report$default(Lorg/jetbrains/kotlin/cli/common/messages/MessageCollector;Lorg/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity;Ljava/lang/String;Lorg/jetbrains/kotlin/cli/common/messages/CompilerMessageSourceLocation;ILjava/lang/Object;)V

or

e: java.lang.IncompatibleClassChangeError: Found class org.jetbrains.kotlin.backend.common.extensions.IrPluginContext, but interface was expected

I've tried Gradle 6.5 and 6.6-rc-3.

@FernandoX7
Copy link

FernandoX7 commented Jul 30, 2020

@TomasKuhn were you able to find a solution to this?

I also tried with gradle 6.6-rc-4 and nothing :/

@TomasKuhn
Copy link

There is no solution yet. It's defined in Gradle, so we have to wait on new Gradle version which use Kotlin 1.4 for kotlin-dsl

@StefMa
Copy link
Contributor

StefMa commented Jul 31, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants