How do you get access to the Project instance from...
# community-support
l
How do you get access to the Project instance from within an artifact transform? I need it to use information from another plugin.
m
Most probably you can't. You'll have to pass the needed data as arguments, like you would do for a task
l
I suppose I can do that, since my plugin is also going to be the one instantiating the artifact transforms anyway. But in case someone tries to do it themselves, is there a way to set a convention on an artifact transform's parameters object?
m
This should include
Property<>
that can have conventions
l
Are conventions applied to every possible instance of the enclosing type?
Gradle does a lot of metaprogramming, so it's hard to keep track of what's single-instance and what's global
m
A convention on a property is just a default value
If you set it with
property.convention("foo")
I would expect it to work. I'm not the most artifact transform expert though so take this with a grain of salt
Gradle is

just code

at the end of the day
v
Are conventions applied to every possible instance of the enclosing type?
Conventions are set where you set them, simple but true. :-)
l
Conventions are set where you set them, simple but true. :-)
That's really vague, so I want to make sure I understand: When you do
val x = project.objects.newInstance<MyType>(); x.someProperty.convention("foo")
, you are only setting the default value for
x
and not for every instance of
MyType
?
v
Yes, of course. Everything else would be very strange and unintuitive imho. :-)
Convention doesn't mean for that property for all instances. Convention means, that this is the conventional value for that instance, which is used if the user does not set an explicit value and which is also used if the user did set an explicit value but resets the explicit value to
null
.