I am trying to grok the usage of @Nested
for task inputs, but seem to be failing. Specifically having trouble understanding how @Nested
and nested property conventions work.
At a high-level, I have a DSL extension and part of its state will be used as a nested-input for a task.
class MyPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
...
MyDslExtension dsl = project.getExtensions().create( "abc", MyDslExtension.class, project );
project.getTasks().create( "generateDescriptor", GenerateDescriptor.class, dsl );
}
}
class abstract MyDslExtension implements ExtensionAware {
private final Descriptor descriptor;
@Inject
public MyDslExtension(Project project) {
descriptor = project.getObjects().newInstance( Descriptor.class, project );
}
@Nested
public Descriptor getDescriptor() {
return descriptor;
}
}
class abstract Descriptor implements ExtensionAware {
private final Property<String> description;
private final MetadataDescriptor metadataDescriptor;
...
@Inject
public Descriptor(Project project) {
description = project.getObjects().property(String.class);
description.convention( "stuff" );
metadataDescriptor = project.getObjects().newInstance( MetadataDescriptor.class, project );
}
@Input
Property<String> getDescription() { ... }
@Nested
MetadataDescriptor getMetadataDescriptor() { ... }
}
class abstract MetadataDescriptor implements ExtensionAware {
private final ListProperty<String> keywords;
...
@Inject
public MetadataDescriptor(Project project) {
keywords = project.getObjects().listProperty(String.class);
}
...
}
abstract class GenerateDescriptor extends DefaultTask {
private MyDslExtension dsl;
@Inject
public GenerateDescriptor(MyDslExtension dsl) {
this.dsl = dsl;
}
@Nested
public Descriptor getDescriptorDetails() {
return dsl.getDescriptor();
}
}
Roughly, the plugin adds MyDslExtension
as a project DSL extension and a GenerateDescriptor
task, which uses the Descriptor
portion of the MyDslExtension
for its input.
The problem seems to be with property conventions not being honored if the property is part of a Nested structure.
Some problems were found with the configuration of task ':generateDescriptor' (type 'GenerateDescriptor').
- In plugin 'xyz' type 'GenerateDescriptor' property 'descriptorDetails.description' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
1. Assign a value to 'descriptorDetails.description'.
2. Mark property 'descriptorDetails.description' as optional.
- <rinse, repeat for each property with a convention>
Why don’t these task conventions take affect?
Thanks!