How to skip artifactoryPublish task if nothing changes?

On the continuous build server I the following against all my projects in the right order of dependencies.

gradlew build artifactoryPublish

I don’t do clean, because my goal is to have the faster incremental build as possible.

Right now, it’s kind of optimized except for that “artifactoryPublish” it keep publishing artifact that didn’t change.

How can I make it not doing anything if nothing else changed?

I assume the jar task shows as up-to-date? Perhaps you could do something like this?

artifactoryPublish {
  onlyIf { jar.didWork }
}

To do this properly you need to compare the checksums of the logical equivalent on the server of what was built and the locally built version.

There’s nothing built in to do such remote checksumming automatically. You’ll need to work out the URL to the corresponding URL of the checksum file on the server, get it, then compare it to the local thing. If you can write this logic, you can use the ‘upToDateWhen {}’ method of ‘artifactoryPublish.outputs’.

In general I agree with what Luke mentioned, but I think the artifactory plugin does check if an artifact was uploaded earlier and if that is the case it shortcuts the upload. This is not implemented in a way, that it uses the gradle up-to-date mechanism. This shortcut is not exlicitly exposed to the user. But when calling artifactoryPublish in a 2nd run, you should see that the task runs way faster as no artifacts need to be transported via http.

cheers, René

this works not in every case. imagine the build fails after the jar was built but before the artifactoryPublish task was triggered. This means that in a 2nd run the jar might not be rebuilt (jar.didWork = false) but also not published