I’m trying to write a test for my custom plugin that can apply some other plugins using Gradle 4.6 and TestKit. Here’s what test build file looks like using spock framework:
"""
plugins {
id 'myplugin'
id 'otherplugin' apply false
}
myplugin {
other()
}
"""
That other()
function is optional and when present in a build it applies otherplugin
like:
def other() {
project.plugins.apply: Class.forName('org.otherplugin.Plugin')
// ... and does some other stuff going forward
}
It’s worth to note that myplugin
works fine when used in the actual project but not in a test where this error happens:
* What went wrong:
A problem occurred configuring root project 'junit2470783895365713816'.
> Failed to notify project evaluation listener.
> org.otherplugin.Plugin
Which is just another way to say there was ClassNotFoundException
.
Test execution code itself that runs a build file is very much standard like
GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('build', '--rerun-tasks')
.withPluginClasspath()
.withDebug(true)
.build()
Should this be a supported scenario or some other approach is required in this case? I know there’s an option to pass Iterable
to pluginsClasspath
but otherplugin
is publicly available from plugins portal.