Apply from classes availability for buildscript classpath

When build.gradle has contents like this

apply from: ‘fnd/cmn/bu/BUConsts.gradle’; apply from: ‘fnd/cmn/bu/uts/tng/TNGConsts.gradle’;

I see BUConsts and TNGConsts getting compiled.

However, I am not where these class files get written to… Once this is written to some directory, would such classes available to script without explicitly adding them like this…

buildscript

{

dependencies

{

classpath files([“C:\temp\out\production\lapos”]);

}

}

Regards, Raja Nagendra Kumar, C.T.O www.tejasoft.com

No, this is not supported. You can use classes

  • declared in a parent build script * declared in the ‘buildSrc’ project * coming from an external Jar/class file and added to ‘buildscript.classpath’

You can use classes > declared in a parent build script

Can you provide an example of this?

I tried adding a class declaration to the root build.gradle and then using the class in a subproject build.gradle. I also tried many other combinations, neither worked. It seems I can use classes declared in the same gradle file only (or in buildSrc of course, but I avoid using this option for now).

To use a class declared in a parent script, you have to use some tricks, like assigning the class object to an extra variable, or sharing a factory method rather then the class itself. In most cases it’s better to use ‘buildSrc’.