Thomas Hirsch
Thomas Hirsch

Reputation: 2318

Gradle: How to have an upload task make an up-to-date check?

I'm trying something rather simple: not having an upload task execute a second time for the same version number. I

uploadArchives {
    inputs.file file("version.txt")
    repositories.mavenDeployer {
        // ...
    }
}

And version.txt contains:

1.0.2

However, the task is not show as UP-TO-DATE when I execute the task twice without changing version. I also tried declaring a property as input, to the same effect. I'm probably missing something obvious.

Upvotes: 2

Views: 2202

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123950

The Upload task type doesn't declare any outputs, in which case Gradle plays it safe and assumes that outputs are out-of-date. Try this:

uploadArchives.outputs.upToDateWhen { true }

Now the uploadArchives task should be up-to-date unless either the version file or the contents of the archives to be uploaded have changed (compared to the previous execution of the task on the same machine). The archive contents are declared as an input by the Upload task type.

Note that this won't prevent user/build A from uploading the same version as was uploaded by user/build B. To achieve that, you'd have to implement a local/remote version comparison in outputs.upToDateWhen {}.

Another option is to enforce the "do not override" rule on the repository side.

Upvotes: 3

Related Questions