Setting a property in build.gradle and getting it in custom Plugin

Hi

I am trying to build a custom plugin.

I want to have a property in build.gradle say myMainClass and i like to get the value in my plugin…

i have tried using myPluginConventions and also project.extensions.create but i am unable to get the property from build.gradle.

Can anyone tell me what is the good way to get property inside custom plugin ?

in Extensions i used project.extensions.creaet (“myblock”, MyBlockPluginConvension)

MyBlockPluginConvension is having a variable myMainClass

I tried to get the value in my plugin as project.myblock.myMainClass Its not working!

And for convensions project.convention.plugins.myblock = new MyBlockPluginConvension()

MyBlockPluginConvension is having a variable myMainClass and a closure myblock

inside plugin i am trying myBlockPluginConvension.myMainClass

both are not working !

Hey,

Using extensions, referencing the value via “project.myblock.myMainClass” should work. Can you tell us more details about where you use this reference? What do you mean with “it’s not working”? I suppose, that you reference the property before it is set.

btw. You noticed the typo in your sample code?

project.extensions.creaet

should be

project.extensions.create

To make your posts more readable it would be very helpful to put your sample code in a <code> </code> section.

regards, René

Sorry its my typos here :stuck_out_tongue:

i can access the extension object only in th apply method… but i have written a configureRun(project) and inside that i am trying to access the extension object the object is null!

Can you provide the code of your configureRun(project) method? where is this method declared and where do you call it from?

https://github.com/jugchennai/visage-gradle-plugin this is the plugin i am working on…

i have tried both extension and convenstions but its not working. Not sure why the value is null when i move it to configureRun() method. i can see i can get the value in apply method.