Mutable nested managed property

I’m trying to write a custom task with a mutable nested managed property. But I was only able to get read-only property. Running the build throws an error: “Cannot set the value of read-only property ‘database’ for task ‘:importData’ of type ch.so.agi.gretl.tasks.Ili2pgImport.”

Custom task:

@Nested
public abstract Database getDatabase();

Database class:

public abstract class Database {
    @Input
    public abstract Property<String> getUri();
    
    @Input
    @Optional
    public abstract Property<String> getUser();
    
    @Input
    @Optional
    public abstract Property<String> getPassword();
}

build.gradle:


tasks.register('importData', Ili2pgImport) {
    database =  {
      uri = "jdbc:postgresql://localhost:54321/edit"
    }
}

Any ideas what’s wrong with my task? My build file?

Thanks
Stefan

This works:

    database.uri="jdbc:postgresql://localhost:54321/edit"
    database.user="gretl"

But I’d prefer a more nested syntax.

Stefan

Add the following method to your custom task class:

void database( Action<Database> configAction ) {
    configAction.execute( getDatabase() )
}

Then you will be able to configure it like so:

tasks.register('importData', Ili2pgImport) {
    database {
        uri = "jdbc:postgresql://localhost:54321/edit"
    }
}

Thanks. Works like a charm.