Is there any way to import a class from a custom p...
# gradle
s
Is there any way to import a class from a custom plugin but in custom gradle file that will be later applied to build.gradle? Not able to use the class right now getting error that it can't find it even after mentioning the import statement
b
then the class is probably not publicly accessible in the plugin
a… you said "later". without loading the plugin, it's not possible. but you can load it with
apply (false)
to access the classes without applying the plugin
s
but i can't use plugin block in non build.gradle or settings.gradle files right?
b
You can the depend on it just as a regular dependency?
You might want to do whatever you are trying to accomplish using buildsrc, or does that not work for you?
If I may ask: Why is your logic in a lone file not belongin to anything?
s
so i have created a plugin for handling maven publish related stuff now to add the configs for it, i have to add mavenPublishing block in all the modules, i just want to create a publish-handler.gradle that will attach mavenpublishing in all the subprojects from a single point, just for code clarity
in the handler, i'm not able to use any classes mentioned in the plugin like ArtifactInfo, BuildType (plugin classes, not AGP's)
b
i don't think this is going to work like that, but you can add your publish-handler.gradle to biuldsrc and do it there
v
Taking a step back, where is your
publish-handler.gradle
and how do you use it? Can you maybe show an MCVE of your intended setup?
s
it's in a normal directory in the project and in root projects' build.gradle, i have added apply from: scripts/publish-handler.gradle
the handler looks like this
v
Those are called "legacy script plugins" and are highly discouraged, as they have many quirks and problems. Better make it a proper convention plugin for example in
buildSrc
or an included build, for example implemented as precompiled script plugin.