I ran into an issue with TestKit and Kotlin. I def...
# community-support
m
I ran into an issue with TestKit and Kotlin. I define an extension, e.g.:
Copy code
interface MyLibraryExtension {
  fun getValue(): String
  ...
}
I create such an object and register it as
myLibrary
extension upon applying the plugin. I want to test it with TestKit. In a test project
build.gradle.kts
: • This works:
println(myLibrary::class.java.getMethod("getValue").invoke(myLibrary))
• But this fails:
println(myLibrary.getValue())
with "Unresolved reference: getValue". So Gradle under TestKit: • Finds the extension object just fine. • It can inspect it and use it via reflection just fine. • It cannot deal with the extension without reflection...?! Am I missing something for this to work in TestKit? It all works fine if I try it out on the CLI without TestKit. Update: It even works if I use Groovy
build.gradle
instead of Kotlin
build.gradle.kts
in the test project...
v
This is probably a class loader issue and related to the way the classes are added to the test process. When the accessors for the Kotlin DSL are generated, it must probably does not see the extension class and this generates an accessor that returns
Any
which does not have that method.
If you publish to some file based local repository (but better something dedicated, not Maven Local) and consume the plugin from there in your tests, not using
withPluginClasspath
, it might maybe with better.
But actually I also have test kit tests without such a local publishing and they are working, so I wonder why it is not working. Do you maybe have some MCVE ?