has anyone else seen this issue when trying to test a plugin with test kit, and the plugin uses clas...
w
has anyone else seen this issue when trying to test a plugin with test kit, and the plugin uses classes from the kotlin plugin?
Copy code
* What went wrong:
java.lang.NoClassDefFoundError: org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension
> org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension
and the test script looks like
Copy code
plugins {
   kotlin("jvm") version("1.8.0")
   id("my.plugin")
}
m
Maybe you need
withPluginClasspath()
or so?
w
i do have that
m
As a side note, I usually prefer publishing the plugin to a local maven repository and reuse that from the test project
w
i do not have a dependency on the kotlin plugin in my plugin b/c in me experience, it causes issues downstream such as
Copy code
Class 'kotlin.reflect.KClass' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.
m
Typically the Kotlin Gradle Plugin should be a
compileOnly
dependency so maybe
withPluginClasspath()
doesn't load it, I don't know
w
yeah, this probalem came up when i switch the dep from implementation to compileOnly
maybe there is a better way to solve that other issue above. i found that when an old kotlin plugin is transitively brought in, the com[iler is expecting that language version even if i add
kotlin("jvm") version("1.6.0")
in the build script
m
expected version is 1.4.1.
That's Gradle forcing you on 1.4
TLDR: use
compileOnly
and do not use
withPluginClassPath
Just make your
test
task depends on
publishAllPublicationToSomeLocalMavenRepository
We're doing it here
w
thanks for the help. this helped me understand what was going on
i solved it a different way though
i added the dependency
Copy code
compileOnly(gradleTestKit())
then configured
Copy code
tasks.withType<PluginUnderTestMetadata> {
        pluginClasspath.from(project.sourceSets.getByName("main").compileClasspath)
    }
167 Views