Can I use an @Managed object as an @Input?

I want to use an @Managed object as a task @Input but the generated Model objects from Gradle don’t seem to be serializable. I have some configuration that have a bunch of parameters and I don’t really want to replicate those configuration in tasks. Given that @Managed objects are pretty restricted in the types they allow, is there a way to get them to be used as task inputs?

This is kind of what I want to do

@Managed
public interface X {
  ...
}

public class MyTask  extends DefaultTask{
  private X x;

  @Input
  public getX() {
    return x;
  }

  @TaskAction
  ...
1 Like

You can get the behavior you want by annotating the input with @Nested and placing the appropriate annotations on the properties of the managed type. This is the typical way to handle inputs that are non-serializable complex types and is no different for managed types.

@Managed
public interface X {
    @Input 
    String getSomeProperty()
    ...
}

public class MyTask  extends DefaultTask{
  private X x;

  @Input
  @Nested
  public getX() {
    return x;
  }

  @TaskAction
  ...

Oh yeah @Nested is exactly what I wanted, I have never come across it before in the user guide or anywhere else before. Is it a new feature?

One more thing, it looks like @Input isn’t necessary if @Nested is applied?

    @Input //<--- is @Input necessary here?
    @Nested
    public getX() {
     ...

The implication is the @Input and @Output annotations are always defined on the Complex object itself?