Rewrite archiveVersion in a Gradle plugin

I develop a Gradle plugin that has a task extending AbstractArchiveTask. The target archive (Ruby’s gem) has a little bit different version scheme, then I wanted to rewrite archiveVersion, then archiveFileName and archiveFile accordingly.

What is the best way to do that?

I tried to set convention in the task’s constructor, but it didn’t work at all. (The convention Provider was never called.)

class Gem extends AbstractArchiveTask {
    @Inject
    public Gem() {
        super();
        this.getArchiveVersion().convention(this.getProject().provider(() -> {
            return buildRubyStyleVersionFromJavaStyleVersion(this.getProject().getVersion().toString());
        }));

I then tried to directly set in createCopyAction. It worked for archiveVersion, but archiveFile did not follow the updated archiveVersion.

    @Override
    protected CopyAction createCopyAction() {
        this.getArchiveVersion().set(...)

I’ll finally want to update archiveFile in the plugin. How can I do that?

Ah, sorry, the latter worked in Gradle 6.2.2. I was testing with Gradle 5.5.1.

But, this plugin still supports Gradle 5. Then, my question is:

  • When was this behavior fixed between 5.5.1 and 6.2.2?
  • Do we have any workaround for Gradle 5?

Hmm, updated from set to convention in https://github.com/gradle/gradle/commit/1978ed1e92f52943189beb875c0c5c15d929fffb