Custom Task: Calculated @Input based on other @Input

We are using a code generator that creates java-classes based on a database schema.
To improve the performance of our build I would like to make use of gradle’s up-to-date checking.

The idea is that the task connects to the database and returns a hash based on the schema state.
For this to work the getDbState() needs access to other inputs (dbUrl, dbUsername and dbPassword).

class JooqTask extends DefaultTask {

    @Input
    String dbUrl

    @Input
    String dbUsername

    @Input dbPassword

    @Input
    String getDbState() {
        // connect to database
        // calculate hash
        return hash
    }
}

What is the correct way to have dependencies between @Input elements?
e.g how can I be sure that dbUrl, dbUsername and dbPassword are initialized before the getDbState() (@Input) is resolved?

Hi,

I think you are looking to this:

class JooqTask extends DefaultTask {

    @Input
    String dbUrl

    @Input
    String dbUsername

    @Input dbPassword

    JooqTask() {
        outputs.upToDateWhen {
            // connect to database
            // calculate hash
            // check hash against local hash saved in build/tmp/db_state file
        }
    }
}

You could also try to have a look at build caching features, that could also be a solution to your needs. https://docs.gradle.org/current/userguide/build_cache.html

Thanks Pierre, using outputs.upToDateWhen solved my problem.