Reading a value from Model in Groovy

So the docs say that you read a value from model with $.myval. Which is fine. Problem seems that it only works from a build.gradle file. When i try that from a groovy file (where 100% of my code is) i get compile errors for invalid syntax. I have yet to find any way to read a value from the model into Groovy. is there one?

I have been playing with Model for about a week now, it seems like people should stay away from it and simply use extensions (much simpler) for a few more years. does that sound about right?

Not sure what you are looking for but you can get access to objects in the form of

project.modelRegistry.find('docker',ManagedDocker)

Gives you access to a type of ManagedDocker1 which is named docker. You can then access the properties of the ManagedDocker instance. This is pretty useful for testing.

HTH

Hey Willie,

The $.myval construct only work in a model DSL from within a .gradle script. To create rules for the model inside plugins, use the rule source approach.

As Schalk mentioned, you can also use project.modelRegistry of type ModelRegistry. However, this is not yet documented in the public API (it is consider internal API) and the documentation is only available inside the code. My recommendation would be to avoid using the ModelRegistry if you can workaround with the public API.

Don’t hesitate to ask more questions,

Daniel

Yes, I forget to add the disclaimer.

Thanks guys, thats pretty much what i was thinking too. Ill hold off till it matures a bit more.