Unable to serialize @Input List<String> from @Managed item in a Task using @Nested

I believe this is a bug, but maybe it’s just not a supported features (seems unlikely)

Looks similar to this, but with a @Nested tag : Workaround for @Input List<String> args is not serializable

I’m using @Nested to try to serialized a @Managed object in my task.

public class PrintStringsTask extends DefaultTask {
  private TestModel testModel;

  @Nested
  public TestModel getTestModel() {
    return testModel;
  }
  
   @TaskAction ....
}

The managed object looks like this

@Managed
public interface TestModel {

  @OutputDirectory
  File getTarget();
  void setTarget(File target);

  @Input
  List<String> getStrings();
  void setStrings(List<String> strings);
}

When I try to run the task, the serialization fails because it fails to serialize the List

Could not add entry ':printStrings' to cache taskArtifacts.bin (/home/userX/src/listSerialization/test-project/.gradle/3.0/taskArtifacts/taskArtifacts.bin).
> Unable to store task input properties. Property 'testModel.strings' with value '[goose]' cannot be serialized.

If you try to figure out the type that it’s trying to serialize, you find it is

org.gradle.model.internal.manage.schema.extract.ScalarCollectionNodeInitializerExtractionStrategy$ListBackedCollection

which doesn’t appear to be Serializable. What exactly is going here? Even if I seed the model element with an ArrayList<String>() (known Serializable), it’s converting it to a non-serializable collection when returning it from the Model and my task input/output saver just fails.

See Test project here https://github.com/loosebazooka/listSerialization for recreation.

1 Like