https://kotlinlang.org logo
Title
j

Justin Ryan

04/26/2019, 5:51 PM
Has anyone had luck with writing a kotlin subplugin with Gradle's TestKit? They don't seem to be happy together, because of the ServiceLoader logic that SubpluginEnvironment does with class loaders. I see that even Kotlin's tests don't use TestKit. 😞 I'd love to have a TestKit based test for a compiler plugin I'm writing.
e

eskatos

04/26/2019, 5:57 PM
TestKit might create some classloading issues when using
runner.withDebug(true)
, it should not cause trouble when not using that
s

snowe

04/26/2019, 6:55 PM
what is the difference between a plugin and subplugin?
e

eskatos

04/26/2019, 8:10 PM
it’s not a Gradle thing the Kotlin Gradle Plugin has a notion of “sub plugin”
j

Justin Ryan

04/26/2019, 9:17 PM
Subplugins is a Kotlin gradle plugin concept. It wants to load the compiler plugins, and it uses a ServiceLoader to do it. Then uses the Subplugins to tied the configuration in the Gradle plugin to the corresponding compiler plugin.
s

snowe

04/26/2019, 9:18 PM
I see.
woah... I just googled something completely unrelated and found you and your name as the main answer on an SO post @Justin Ryan 😂
spoopy
j

Justin Ryan

04/26/2019, 9:29 PM
I've only got online one SO post, so that is quite a coincidence. 🙂
so crazy haha
j

Justin Ryan

04/26/2019, 9:32 PM
@eskatos I concur that debug changes things. When I run without debug, I get identical behavior though, as in it never sees my subplugin. It could be for another reason, but it's suspicious.
e

eskatos

04/27/2019, 10:33 AM
it is suspicious fwiw, TestKit without
withDebug
just runs a regular Gradle daemon
ah, but there’s also
withPluginClasspath
that does a nasty trick to get the plugin under development in the classloader hierarchy
what you could try is automate publishing your plugin to a local repository and then reference that repository in your builds under test, to really mimic real world conditions
if you have a reproducer for the issue with
withPluginClasspath
, could you please open an issue on gradle/gradle?
j

Justin Ryan

04/29/2019, 4:05 PM
Thanks @eskatos. I remember the days of publishing to a local repo for testing. I'll give it a try to unblock myself. For an issue, there's a few pieces involved. I'll see if I can pair down the minimal project I'm working with: https://github.com/quidryan/debuglog/blob/plugin-unit-tests/gradle-plugin/src/test/kotlin/debuglog/DebugLogGradlePluginTest.kt It's from a small addition to @kevinmost’s debuglog example project.