0
votes

Yes, I do need to apply both the 'maven' and 'artifactory' plugins. However, there are many, many existing Jenkins jobs which explicitly call 'uploadArchives' (supplied by the maven plugin). I would like to override that in my own plugin to force it to call 'artifactoryPublish' when 'uploadArchives' is used.

I want to do this programmatically in my plugin, rather than changing hundreds of build.gradle files, and I have tried every combination of calls I can think of with no luck so far.

The last caveat is that this has to work back to Gradle 2.4 at a minimum, as the gradle wrapper is being used and several different versions of gradle are invoked over a set of builds.

Anyone have an idea on how to accomplish this?

Here's the latest thing I tried:

project.getTasks().replace('uploadArchives', MyTask)

Although the constructor is called (verified by a println message), the task itself is never called (verified by adding an explicit 'throw' statement and never seeing the exception).

1
Do you necessarily have to override the task? Would supplement work? - RaGe
Also, once you succeed in building your plugin, don't you have to then add your plugin to the hundreds of build.gradle files? - RaGe
I don't want anyone to use uploadArchives any longer, but there are possibly a few hundred existing automated jobs which call it. So it would be helpful if the jobs called my stuff instead, without having to change all those jobs. As for adding my plugin, that's already being done - I'm just changing implementation. - Jamie Cooper

1 Answers

0
votes

Just to clarify...

I want to override uploadArchives for 3 main reasons:

  • Many existing jobs (as well as programmer's fingers) with uploadArchives programmed in.

  • We WANT the extra info artifactoryPublish creates and uploads, especially if done via the Jenkins plugin, so you get Jenkins job number, etc.

  • We do NOT want anyone using plain uploadArchives and publishing WITHOUT the extra build info.

I finally found the answer myself... it's not exactly straightforward, but does work as we wished, except for the extra output line about uploadArchives during a build.

    project.plugins.apply('com.jfrog.artifactory')
    project.getTasks().create([name: 'uploadArchives', type: MyOverrideTask, overwrite: true, dependsOn: ['artifactoryPublish'] as String[], group: 'Upload'])

Yes, I could have just disabled uploadArchives after making it depend on artifactoryPublish, but then instead of just printing 'uploadArchives' during the build, it prints 'uploadArchives [Skipped]', and we didn't want there to be any confusion.