I searched around and found that this only works if ToolSetup has a name property. I reworked ToolSetup to be:
abstract class ToolSetup {
private final String name
public ToolSetup(String name) {
this.name = name
}
String getName() {
return name
}
abstract Property<File> getArgsFile()
}
I’m getting the following:
Cannot set the value of read-only property ‘argsFile’ for object of type ToolSetup$Inject.
I also tried explicitly calling argsFile.set(file(...)), but this gives me the same error. I also tried to explicitly create Property instances using ObjectFactory, but still got the same.
I already wrote a plugin that does something similar, where it works, but that plugin is written in Java. I’m guessing there’s some trivial mistake here related to Groovy and letting Gradle manage the implementation for me, which I’m not seeing. I’d be very grateful if someone could point it out.
I still get the same error when calling gradle properties:
Cannot set the value of read-only property ‘argsFile’ for object of type ToolSetup$Inject.
I tried both the Gradle version I was using (7.4.2) and also the latest one (7.6), but both fail.
I noticed that you mentioned using argsFile.set(...). That does work. I’m confused, though, as to why = doesn’t work. The example on developing custom plugins shows this syntax (Developing Custom Gradle Plugins):
The bug seems to be related to project.container(). Using project.object.domainObjectContainer() doesn’t lead to the error. More details in the issue in Github issue.