Implemented properties of a Managed type are not accessible using model path

Given a managed model type as followed:

@Managed
public abstract class MyManagedType {
    public abstract String getProp1();
    public abstract void setProp1(String prop1);

    public String getProp2() {
        return getProp1.toUpperCase();
    }
}

The prop1 property is managed and it’s value can be references in a rule using @Path(<xyz>.prop1), but prop2 cannot be referenced using @Path(<xyz>.prop2). Similarly in gradle script prop1 can be accessed as $.<xyz>.prop1 while prop2 cannot be accessed as $.<xyz>.prop2.

The difference between prop1 and prop2 is an implementation detail and should not impact the way these properties are accessed in rules or in a gradle script.

The workaround, I used, is to convert prop2 as a managed property and set it in a @Finalize rule, but this is not fully satisfying. It adds some boilerplate code and this property is really a read-only property so it shouldn’t have a setter. With this workaround one can, by mistake, mutate prop2 in a @Mutate rule without error while the value will eventually be replaced by the value set by the @Finalize rule.

This looks to be a limitation of the model DSL. You can get around this by doing the following:

def foo = $.foo
println foo.prop2

I’ve GRADLE-3452 to track this issue.