Can't access classes from plugin directly in included script


(Markus Oley) #1


We have some plugins on our own, which we apply in our build.gradle. Also we apply a second buildscript afterwards, which handles our tests, the following way:

apply {
plugin 'ownplugin’
from ‘tests.gradle’

In the tests.gradle we want to create a task of a type, which classfile is located in the ownplugin.

task executeImportBla(type: mycompany.plugin.BlaTask) {
… some configuration

This works, if the task creation happens in the build.gradle but doesn’t work if it happens in the tests.gradle. The error is:
Caused by: groovy.lang.MissingPropertyException: Could not find property ‘mycompany’ on root project ‘project’.
at org.gradle.api.internal.AbstractDynamicObject.propertyMissingException(
at org.gradle.api.internal.AbstractDynamicObject.getProperty(

If I add an import of the taskclass before and only use simplename when creating task, the class could not be found when importing. And again: in build.gradle the whole stuff is working.

Is this a bug or do I try to do something that is not possible?

Any help welcome,
Thank you

(Stefan Oehme) #2

Script plugins do not have access to the main buildscript classpath.

You could:

  • add a dependency on mycompany.plugin to tests.gradle using the buildscript {} syntax
  • push the logic from tests.gradle into a plugin class in the buildSrc folder of your project, giving you the added benefit of more IDE support when editing it

(Markus Oley) #3

OK, thank you for your solutions