allegro / axion-release-plugin

Gradle release & version management plugin.
https://axion-release-plugin.readthedocs.io/
Apache License 2.0
562 stars 155 forks source link

branchVersionIncrementer cannot be serialized #590

Open savasimic opened 1 year ago

savasimic commented 1 year ago

I tried to use different custom incrementers for different branches. When executing task currentVersion I was receiving error like:

* What went wrong:
Execution failed for task ':currentVersion'.
> Cannot fingerprint input property 'versionConfig.branchVersionIncrementer': value '...' cannot be serialized.

I tried to set branchVersionIncrementer with same values like in documentation

scmVersion {
    branchVersionIncrementer = [
            'feature/.*' : 'incrementMinor',
            'bugfix/.*' : { c -> return c.currentVersion.incrementPatchVersion() },
            'legacy/.*' : [ 'incrementMinorIfNotOnRelease', [releaseBranchPattern: 'legacy/release.*'] ],
    ]
    checks {
        uncommittedChanges.set(false)
    }
}

and got same error

* What went wrong:
Execution failed for task ':currentVersion'.
> Cannot fingerprint input property 'versionConfig.branchVersionIncrementer': value '{feature/.*=incrementMinor, bugfix/.*=build_ahvhhwjkzwvr3796kswh2j1q4$_run_closure1$_closure5$_closure12@7d8e0d33, legacy/.*=[incrementMinorIfNotOnRelease, {releaseBranchPattern=legacy/release.*}]}' cannot be serialized.

This is happening only when I'm using closures.

Did anyone had similar issue?

Just to note, I'm using gradle 7.5 and version of axion-release-plugin 1.14.4.

bgalek commented 1 year ago

hi! @savasimic could you create a repo than we can debug on? maybe we introduced some problems when adding kotlin dsl support - did it work on any version for you?

savasimic commented 1 year ago

Hi @bgalek , here is sample repository with reproduced issue. I included 2 branches where I'm running currentVersion task for 1.13.14 and 1.14.4 versions of axion-release plugin:

duschata commented 1 year ago

Hi All, I've the same issue and have created a test here: https://github.com/duschata/axion-release-plugin/blob/main/src/integration/groovy/pl/allegro/tech/build/axion/release/BranchVersionIncrementerTest.groovy

This test will allways fail since version 1.14.0 because the introduction of the @Input annation with this commit: https://github.com/allegro/axion-release-plugin/pull/516

The simple fix is to remove the @Input annotation above

    @Optional
    abstract MapProperty<String, Object> getBranchVersionIncrementer();

Probably these (and also other) @Input annotations are usesless at this point because the closure is always evalated at configuration time and there is no expensive input/output (writing) task which needs caching,

Is it possible to remove them in 1.15.1? Kind regards, Tom

bgalek commented 1 year ago

@duschata nice! thx! Do you want to make a PR and remove unnecessary annotations? I can do it next week probably - and I'll be happy to release new version

jjohannes commented 1 year ago

@duschata I think the "better" fix would be to use the @Internal annotation.

    @Internal
    abstract MapProperty<String, Object> getBranchVersionIncrementer();

This clearly indicates to Gradle that this is something that is not part of the Task input. And it would be consistent with:

    @Internal
    abstract Property<VersionProperties.Incrementer> getVersionIncrementer()

in the same file.

I think @Optional can be left out, as it has no real effect on a Map/List (There is always an empty Map/List).