gradle-release icon indicating copy to clipboard operation
gradle-release copied to clipboard

Version 3.0.0: `requireBranch` property is final and cannot be overridden

Open arjanvlek opened this issue 2 years ago • 7 comments

We're releasing from the development branch to the master branch. The following configuration works fine in version 2.8.1 of the plugin, but breaks in 3.0.0:

release {
    pushReleaseVersionBranch = 'master' // Release to master
    tagTemplate = 'v${version}'

    git {
        requireBranch = 'development' // Release from development
    }
}

With version 3.0.0, we're getting the following error message:

A problem occurred evaluating root project '<<projectname>>'.
> Cannot set the property 'requireBranch' because the backing field is final.

We need to override the requireBranch property, because we are not releasing from main (or previously master) branch but from development. The readme indicates this is still a valid configuration setting, so I wouldn't have expected this to break.

Versions I'm using:

------------------------------------------------------------
Gradle 7.4.1
------------------------------------------------------------

Build time:   2022-03-09 15:04:47 UTC
Revision:     36dc52588e09b4b72f2010bc07599e0ee0434e2e

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.1 (Eclipse Adoptium 17.0.1+12)
OS:           Mac OS X 11.4 x86_64

OS version is not right, my Intel Mac is running macOS 12.4 so i don't know why it says 11.4.

arjanvlek avatar Jun 24 '22 09:06 arjanvlek

HI, I'm having the same problem. Using

release {
    git.requireBranch = 'master'
}

Doesn't work either. The error is:

A problem occurred evaluating root project '<project-name>'.
> Cannot set readonly property: requireBranch for class: net.researchgate.release.GitAdapter$GitConfig

ColdFireIce avatar Jun 24 '22 09:06 ColdFireIce

I faced that too, and agree that it's not normal, but the following workaround works:

release.git.requireBranch.set('master')

xvik avatar Jun 24 '22 09:06 xvik

I faced that too, and agree that it's not normal, but the following workaround works:

release.git.requireBranch.set('master')

Thank you very much. This worked for me.

ColdFireIce avatar Jun 24 '22 11:06 ColdFireIce

I have the same problem, but with litte different error.

release {
    // ...
    git {
        requireBranch = 'master'
    }
}

Results in the following error: Cannot cast object 'main' with class 'java.lang.String' to class 'org.gradle.api.provider.Property'

I think that the error from @arjanvlek is related to mine, because the releaseBranch property is declared final and initialized in the Constructor of GitAdapter.GitConfig. I think it would be possible to fix this error by initializing all properties of GitAdapter.GitConfig inline, without using the Constructor.

Configuring the following beforementioned workaround in build.gradle works for me too:

release {
    // ...
    git {
        requireBranch.set('master')
    }
}

However, this workaround is not intentional. The Gradle Documentation for Lazy Evaluation states: Note that Gradle Groovy DSL generates setter methods for each Property-typed property in a task implementation. These setter methods allow you to configure the property using the assignment (=) operator as a convenience.

Please provide a fix for the root problem, as this plugin is not conform to Gradle documentation anymore.

BTW: The documentation of this plugin in README.md is not correct anymore, as requireBranch and other properties of git block cannot be set anymore with assignment operator.

djessich avatar Jun 24 '22 11:06 djessich

FYI, the problem was introduced here in this commit: https://github.com/researchgate/gradle-release/pull/356/commits/a4a29c1d3a6a61c65462de38961217b32239c588#diff-e153b6a5c5ad5979271a2f7e4b409cd2357bb11a25d1498d1e374d3cb1eabe77R39-R40

Ping @Hillkorn

nre-ableton avatar Jul 15 '22 08:07 nre-ableton

It seems the following also does not work anymore

release {
    git.requireBranch.set("release/.*")
}

My release just failed saying I was not on the main branch. Event though we set the requireBranch

Strangely enough all commits and the actual release of the artifact went correctly?

Shuyinsama avatar Feb 06 '23 09:02 Shuyinsama