Custom kotlin plugin error: loader constraint violation #84

Closed
Evgen1000end opened this Issue Jun 29, 2016 · 0 comments

Projects

None yet

2 participants

@Evgen1000end
Evgen1000end commented Jun 29, 2016 edited

i wrote plugin on Kotlin and i'm trying use it.

Plugin:

open class ExampleTask: DefaultTask() {
var from:String = "default from value"

open fun lambdaExample(setup:(String)->String):String{
return setup(from)
}

@TaskAction
open fun send(){
val res = lambdaExample { "it = $it" }
println(res)
}
}

Call:

task < ExampleTask > ("overriding task"){
from = "new value"
val res = lambdaExample { "[$it]" }
}

Script not compile with error

Loader constraint violation: when resolving method "com.home.ExampleTask.lambdaExample(Lkotlin/jvm/functions/Function1;)Ljava/lang/String;" the class loader (instance of org/jetbrains/kotlin/codegen/GeneratedClassLoader) of the current class, Build_gradle$4, and the class loader (instance of org/gradle/internal/classloader/VisitableURLClassLoader) for the method's defining class, com.home.ExampleTask, have different Class objects for the type kotlin/jvm/functions/Function1 used in the signature

What am I doing wrong?

@bamboo bamboo added this to the 0.3.0 milestone Jul 1, 2016
@bamboo bamboo self-assigned this Jul 12, 2016
@bamboo bamboo added a commit that closed this issue Jul 19, 2016
@bamboo bamboo Use isolated ClassLoader for Kotlin jars
Due to the lack of isolation between gradle-script-kotlin and the
compiled buildscript(s), referenced Kotlin types could leak into
different ClassLoader scopes causing all sorts of loader constraint
violations. That lack of isolation also meant that only the specific
version of Kotlin shipped with gsk could ever be used.

This commit mitigates these limitations by subverting the ClassLoader
delegation model when Kotlin jars are detected in the buildscript
classpath. In that case, all jars in the script classpath together with
the Kotlin jars are segregated into a ClassLoader that will first try to
load classes locally before delegating to its parent from the
ClassLoader scope hierarchy.

This solution is only a stepping stone and comes with its own set of
limitations, buildscript block and script body cannot exchange Kotlin
library values for one. A better solution will demand more isolation
between gradle-script-kotlin and core.

Resolves #84
Resolves #86
Resolves #25
a37751a
@bamboo bamboo closed this in a37751a Jul 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment