How do I make a method/member from a parent interface @Unmanaged for a rule based build?


(Appu Goundan) #1

Imagine some external library that defines its model using interfaces

public interface ModelX {
  Collection<Path> getStuff();

  String getSomething();

I am extending this model into a gradle managed object with explicit overrides

public interface GradleModelX extends ModelX {
  @Unmanaged Collection<Path> getStuff();
  @Unmanaged void setStuff(Collection<Path> stuff);

  String getSomething();
  void setSomething(String something);

This is useful to me because I can now pass GradleModelX objects to all methods in my library that take ModelX. I know Path is not a managed type, so I was thinking I could do the conversions for Paths myself and mark it as @Unmanaged

When gradle tries to build this model, it fails with

Caused by: org.gradle.model.internal.core.ModelTypeInitializationException: A model element of type: 'com.whatever.GradleModelX' can not be constructed.
Its property 'java.util.Collection<java.nio.file.Path> stuff' can not be constructed

The gradle annotation processing for rule based configurations seems to go inspect the parent class ModelX', because even though I’m marking those methods as Unamanged in GradleModelX, it complains that stuff cannot be instantiated because it’s not an accepted type. I don’t want to go annotate the model in the other library where ModelX is defined, because it’s not a gradle exclusive interface, it woudn’t be meaningful.

Is there any useful way I can do this without changing ModelX and still extending it in GradleModelX.