How do I override the 'uploadArchives' task programmtically, in my own plugin?

The uploadArchives task is defined already. I need to override the functionality of this task so that all uploads go to Artifactory rather than Maven repositories.

I have an existing plugin which sets up the uploadArchives configuration, which I can replace with setting up the artifactory{} configuration. However, I also need to override calling ‘uploadArchives’ as a task, such that it performs a simple ‘artifactoryPublish’.

The reason for doing this is hundreds of existing jobs in Jenkins, developer playpens, etc., etc. that already exist and are calling ‘uploadArchives’. I want my code to replace the implementation as seamlessly as possible, such that a developer (or Jenkins job) can continue typing ‘gradle clean build uploadArchives’ and the only difference (besides the fact that artifactoryPublish actually tells you what it is doing) is that the built objects will go to an Artifactory instance instead of a Maven repo.

I have tried many different ways, and have yet to get any thing other than disabling uploadArchives.

The main caveat of this is that whatever solution exists needs to work backwards to Gradle 2.4, up through 2.11 and beyond.

I’m not sure why you want to replace the existing functionality, as uploadArchives can simply be configured with a different repository. However, for programmatically setting the repository, perhaps taking a look at or * will give you some pointers.

uploadArchives {
    repositories {
       // define your target repository here

I want to replace for 2 reasons:

  1. We need the extra build info metadata the artifactory plugin creates and uploads along with the artifacts.
  2. We do not want anyone publishing with ‘uploadArchives’ as it will publish without that extra build info.

I was well aware I could point uploadArchives to an artifactory instance - that’s what we were already doing.

The other advantage of the extra build info is that if you use Jenkins, and allow it to handle all the details of publishing to artifactory, it adds extra info to what the artifactory plugin produces, including a URL back to the Jenkins job instance which created the objects published. A handy way to get back to the build log, without having to keep track of it yourself.